connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java
author dadubrow
Wed, 06 Jan 2010 13:32:23 -0600
changeset 748 7bd40a2d0a18
parent 730 8ecd45ef360e
child 749 22f0d10fce10
permissions -rw-r--r--
Add connection status reconciliation + fixes + tweaks
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     1
/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     8
*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    11
*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    12
* Contributors:
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    13
*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    14
* Description: 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    15
*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    16
*/
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    17
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    18
package com.nokia.carbide.remoteconnections.internal.ui;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    19
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    20
import java.text.MessageFormat;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    21
import java.util.ArrayList;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    22
import java.util.Collections;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    23
import java.util.Comparator;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    24
import java.util.List;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    25
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    26
import org.eclipse.jface.layout.GridDataFactory;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    27
import org.eclipse.jface.layout.GridLayoutFactory;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    28
import org.eclipse.swt.SWT;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    29
import org.eclipse.swt.custom.CLabel;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    30
import org.eclipse.swt.events.MouseAdapter;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    31
import org.eclipse.swt.events.MouseEvent;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    32
import org.eclipse.swt.events.SelectionAdapter;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    33
import org.eclipse.swt.events.SelectionEvent;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    34
import org.eclipse.swt.graphics.Image;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    35
import org.eclipse.swt.graphics.Point;
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    36
import org.eclipse.swt.graphics.Rectangle;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Composite;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    38
import org.eclipse.swt.widgets.Control;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    39
import org.eclipse.swt.widgets.Display;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    40
import org.eclipse.swt.widgets.Menu;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    41
import org.eclipse.swt.widgets.MenuItem;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    42
import org.eclipse.swt.widgets.Shell;
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    43
import org.eclipse.swt.widgets.ToolBar;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    44
import org.eclipse.swt.widgets.ToolItem;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    45
import org.eclipse.swt.widgets.ToolTip;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    46
import org.eclipse.ui.IWorkbench;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    47
import org.eclipse.ui.IWorkbenchWindow;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    48
import org.eclipse.ui.PartInitException;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    49
import org.eclipse.ui.PlatformUI;
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    50
import org.eclipse.ui.menus.CommandContributionItem;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    51
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    52
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    53
import com.nokia.carbide.remoteconnections.Messages;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    54
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    55
import com.nokia.carbide.remoteconnections.interfaces.IConnection;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    56
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    57
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    58
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    59
import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    60
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    61
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    62
import com.nokia.carbide.remoteconnections.internal.registry.Registry;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    63
import com.nokia.carbide.remoteconnections.view.ConnectionsView;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    64
import com.nokia.cpp.internal.api.utils.core.TextUtils;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    65
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    67
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    68
/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
 * This widget appears in the Eclipse trim and allows the user to select the
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    70
 * "default" device connection and also see its status at a glance.
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    71
 * <p>
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    72
 * Note: the UI for this control should behave similarly to that of the News Reader
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    73
 * trim.  Due to the way we're modifying the icon and the state dynamically
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    74
 * for this contribution, they can't be implemented the same way, however.
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    75
 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    76
@SuppressWarnings("deprecation")
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    77
public class ConnectionStatusSelectorContribution extends WorkbenchWindowControlContribution {
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    78
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    79
	/**
724
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
    80
	 * This is the id on the command in the toolbar contribution associated with this 
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    81
	 * widget.  Keep this in sync with the extension point!
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    82
	 */
724
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
    83
	private static final String OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID = "openRemoteConnectionsView";
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    84
	private Composite container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    85
	private CLabel connectionInfo;
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    86
	private ToolItem connectionIcon;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    87
	private IConnectionsManager manager;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
	private IConnection defaultConnection;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    89
	private ListenerBlock listenerBlock;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    90
	private ToolTip tooltip;
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
    91
	private MouseAdapter toolbarListener;
724
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
    92
	private ToolBar toolbar;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    93
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    94
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    95
	 * Contains all the listeners.  In most cases we just recreate the contribution status item.
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    96
	 */
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
    97
	class ListenerBlock implements IConnectionListener, IConnectionsManagerListener, IConnectionStatusChangedListener {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    98
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    99
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   100
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   101
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   102
		public void connectionAdded(IConnection connection) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   103
			updateUI();
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   104
			boolean display = (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic());
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   105
			if (display)
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   106
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   107
						Messages.getString("ConnectionStatusSelectorContribution.AddedConnectionFormat"),  //$NON-NLS-1$
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   108
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   109
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   110
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   111
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   112
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   113
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   114
		public void connectionRemoved(IConnection connection) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   115
			updateUI();
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   116
			boolean display = (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic());
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   117
			if (display) 
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   118
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   119
						Messages.getString("ConnectionStatusSelectorContribution.RemovedConnectionFormat"),  //$NON-NLS-1$
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   120
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   121
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   122
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   123
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   124
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#defaultConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   125
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   126
		public void defaultConnectionSet(IConnection connection) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   127
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   128
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   129
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   130
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   131
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged()
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   132
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   133
		public void connectionStoreChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   134
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   135
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   136
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   137
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   138
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged()
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   139
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   140
		public void displayChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   141
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   142
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   143
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   144
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   145
		 * @see com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatusChangedListener#statusChanged(com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   146
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   147
		public void statusChanged(IConnectionStatus status) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   148
			updateConnectionStatus(status);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   149
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   150
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   151
	}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   152
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   153
	public ConnectionStatusSelectorContribution() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   154
		manager = RemoteConnectionsActivator.getConnectionsManager();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   155
		listenerBlock = new ListenerBlock();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   156
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   158
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   160
	 * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   161
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   162
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
	protected Control createControl(Composite parent) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   165
		// This UI is recreated whenever the default connection changes.
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   166
		
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   167
		// This is gross.  The normal parent of this is a toolbar,
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   168
		// but we cannot add arbitrary stuff to the toolbar besides
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   169
		// this control.  (If you try, it will usually show up
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   170
		// out of order!)
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   171
		//
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   172
		// But we want to have a toolbar button for the connection icon
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   173
		// for which we can change the tooltip and image, and attach 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   174
		// a mouse listener responds to left and right clicking.
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   175
		//
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   176
		// In order to do this, we need to poke around in the widget tree
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   177
		// to find the expected Eclipse-generated toolitem.  Unfortunately,
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   178
		// controlling all this ourselves is even uglier (I tried).
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   179
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   180
		if (parent instanceof ToolBar) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   181
			toolbar = (ToolBar) parent;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   182
			ToolItem[] items = toolbar.getItems();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   183
			for (ToolItem item : items) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   184
				Object data = item.getData();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   185
				if (data instanceof CommandContributionItem &&
724
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
   186
						((CommandContributionItem) data).getId().contains(OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID)) {
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   187
					connectionIcon = item;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   188
					break;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   189
				}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   190
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   191
		} else {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   192
			toolbar = null;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   193
		}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   194
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   195
		container = new Composite(parent, SWT.NONE);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   196
		GridLayoutFactory.fillDefaults().margins(2, 0).applyTo(container);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   197
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   198
		// Create a label for the trim, outside the toolbar.
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   199
		connectionInfo = new CLabel(container, SWT.NONE);
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   200
		GridDataFactory.fillDefaults().grab(false, true).applyTo(connectionInfo);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   201
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   202
		String text = Messages.getString("ConnectionStatusSelectorContribution_NoDefaultConnectionMessage"); //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   203
		defaultConnection = manager.getDefaultConnection();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   204
		if (defaultConnection != null)
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   205
			text = defaultConnection.getDisplayName();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   206
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   207
		connectionInfo.setText(text);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   208
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   209
		attachListeners();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   210
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   211
		updateConnectionStatus(getConnectionStatus(defaultConnection));
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   212
		
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   213
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   214
		// Yuck, toolbars and items have a wonky UI.  We need to do these events on the parent,
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   215
		// since the ToolItem itself is just an area inside the parent.  (#getControl() is only for separators ?!)
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   216
			
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   217
		// On icon: left click = open view, right click = menu
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   218
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   219
		if (toolbar != null) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   220
			if (toolbarListener != null)
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   221
				toolbar.removeMouseListener(toolbarListener);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   222
			
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   223
			toolbarListener = new MouseAdapter() {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   224
				/* (non-Javadoc)
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   225
				 * @see org.eclipse.swt.events.MouseAdapter#mouseDown(org.eclipse.swt.events.MouseEvent)
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   226
				 */
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   227
				@Override
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   228
				public void mouseDown(MouseEvent event) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   229
					ToolItem item = toolbar.getItem(new Point(event.x, event.y));
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   230
					if (item == connectionIcon) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   231
						if (event.button == 1) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   232
							openConnectionsView();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   233
						} else if (event.button == 3) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   234
							Point screenLoc = toolbar.toDisplay(event.x, event.y);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   235
							handleConnectionMenu(screenLoc);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   236
						}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   237
					}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   238
				}
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   239
			};
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   240
			toolbar.addMouseListener(toolbarListener);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   241
			
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   242
			// On label: left or right click = menu
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   243
			connectionInfo.addMouseListener(new MouseAdapter() {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   244
				public void mouseDown(MouseEvent event) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   245
					if (event.button == 1 || event.button == 3) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   246
						Point screenLoc = toolbar.toDisplay(event.x, event.y);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   247
						handleConnectionMenu(screenLoc);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   248
					}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   249
				}
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   250
			});
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   251
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   252
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   253
		RemoteConnectionsActivator.setHelp(container, "ConnectionStatusSelector"); //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   254
		return container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   255
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   256
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   257
	private void handleConnectionMenu(Point screenLoc) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   258
		Shell shell = connectionInfo.getParent().getShell();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   259
		final Display display = shell.getDisplay();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   260
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   261
		final Menu menu = new Menu(shell, SWT.POP_UP);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   262
		populateConnectionMenu(menu);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   263
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   264
		menu.setLocation(screenLoc.x, screenLoc.y);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   265
		menu.setVisible(true);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   266
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   267
		while (!menu.isDisposed() && menu.isVisible()) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   268
			if (!display.readAndDispatch())
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   269
				display.sleep();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   270
		}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   271
		menu.dispose();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   272
	
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   273
	}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   274
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   275
	/**
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   276
	 * @return
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   277
	 */
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   278
	protected void populateConnectionMenu(Menu menu) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   279
		// Display the connections with dynamic ones first, 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   280
		// then static ones, separated by a separator
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   281
	
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   282
		List<IConnection> dynamicConnections = new ArrayList<IConnection>();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   283
		List<IConnection> staticConnections = new ArrayList<IConnection>();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   284
		for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   285
			if (connection instanceof IConnection2 && ((IConnection2)connection).isDynamic()) 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   286
				dynamicConnections.add(connection);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   287
			else
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   288
				staticConnections.add(connection);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   289
		}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   290
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   291
	
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   292
		Comparator<IConnection> connectionComparator = new Comparator<IConnection>() {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   293
			public int compare(IConnection o1, IConnection o2) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   294
				return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   295
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   296
		};
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   297
		Collections.sort(dynamicConnections, connectionComparator);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   298
		Collections.sort(staticConnections, connectionComparator);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   299
	
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   300
		MenuItem label = new MenuItem(menu, SWT.NONE);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   301
		label.setEnabled(false);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   302
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   303
		int number = 1;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   304
		if (dynamicConnections.size() + staticConnections.size() == 0) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   305
			label.setText(Messages.getString("ConnectionStatusSelectorContribution.NoConnectionsDefinedOrDetected")); //$NON-NLS-1$
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   306
		} else {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   307
			label.setText(Messages.getString("ConnectionStatusSelectorContribution_SelectTheDefaultConnectionMessage")); //$NON-NLS-1$
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   308
			
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   309
			for (IConnection connection : dynamicConnections) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   310
				createConnectionMenuItem(menu, connection, defaultConnection, number++);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   311
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   312
			
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   313
			if (!staticConnections.isEmpty())
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   314
				new MenuItem(menu, SWT.SEPARATOR);
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   315
			
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   316
			for (IConnection connection : staticConnections) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   317
				createConnectionMenuItem(menu, connection, defaultConnection, number++);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   318
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   319
		}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   320
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   321
		new MenuItem(menu, SWT.SEPARATOR);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   322
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   323
		MenuItem openView = new MenuItem(menu, SWT.PUSH);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   324
		openView.setText(Messages.getString("ConnectionStatusSelectorContribution.OpenRemoteConnectionsView")); //$NON-NLS-1$
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   325
		openView.addSelectionListener(new SelectionAdapter() {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   326
			@Override
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   327
			public void widgetSelected(SelectionEvent e) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   328
				openConnectionsView();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   329
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   330
		});
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   331
	}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   332
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   333
	/**
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   334
	 * @param menu
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   335
	 * @param connection
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   336
	 * @param defaultConnection 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   337
	 */
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   338
	private MenuItem createConnectionMenuItem(Menu menu, 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   339
			final IConnection connection, 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   340
			IConnection defaultConnection,
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   341
			int number) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   342
		MenuItem item = new MenuItem(menu, SWT.CHECK);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   343
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   344
		boolean isDefault = false;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   345
		isDefault = connection.equals(defaultConnection);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   346
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   347
		item.setSelection(isDefault);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   348
		
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 724
diff changeset
   349
		item.setText(MessageFormat.format("&{0} - {1}", number, connection.getDisplayName())); //$NON-NLS-1$
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   350
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   351
		item.addSelectionListener(new SelectionAdapter() {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   352
			@Override
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   353
			public void widgetSelected(SelectionEvent e) {
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   354
				manager.setDefaultConnection(connection);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   355
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   356
		});		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   357
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   358
		return item;
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   359
	}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   360
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   361
	private void attachListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   362
		manager.addConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   363
		Registry.instance().addConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   364
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   365
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   366
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   367
				((IConnection2) defaultConnection).addStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   368
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   369
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   370
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   371
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   372
	private void removeListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   373
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   374
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   375
				((IConnection2) defaultConnection).removeStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   376
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   377
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   378
		manager.removeConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   379
		Registry.instance().removeConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   380
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   381
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   382
	/*
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   383
	 * (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   384
	 * @see org.eclipse.jface.action.ContributionItem#dispose()
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   385
	 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   386
	public void dispose() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   387
		removeListeners();
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   388
		if (connectionIcon != null)
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   389
			connectionIcon.dispose();
724
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
   390
		if (toolbarListener != null && !toolbar.isDisposed())
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
   391
			toolbar.removeMouseListener(toolbarListener);
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
   392
		if (connectionInfo != null)
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   393
			connectionInfo.dispose();
724
6ab9c30e708f More work to unify the behavior of the Remote Connections status and the News Reader status widgets (bug #10411).
Ed Swartz <ed.swartz@nokia.com>
parents: 723
diff changeset
   394
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   395
		super.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   396
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   397
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   398
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   399
	 * @param ev
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   400
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   401
	protected void openConnectionsView() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   402
		try {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   403
			WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   404
        } 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   405
        catch (PartInitException e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   406
        	RemoteConnectionsActivator.logError(e);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   407
        }
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   408
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   409
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   410
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   411
	 * @param defaultConnection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   412
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   413
	 * @return
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   414
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   415
	private String createConnectionStatusTooltip(IConnection defaultConnection,
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   416
			IConnectionStatus status) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
		if (defaultConnection == null) {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   418
			return Messages.getString("ConnectionStatusSelectorContribution.NoDynamicOrManualConnectionsTooltip"); //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   419
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   420
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   421
		String statusString = null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   422
		if (status != null) {
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   423
			statusString = createStatusString(status);
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   424
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   425
		
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   426
		if (TextUtils.isEmpty(statusString)) {
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   427
			// fallback string; the status should not be empty
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   428
			if (ConnectionUIUtils.isSomeServiceInUse(defaultConnection))
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   429
				statusString = Messages.getString("ConnectionStatusSelectorContribution.InUse"); //$NON-NLS-1$
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   430
			else
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   431
				statusString = Messages.getString("ConnectionStatusSelectorContribution.NotInUse"); //$NON-NLS-1$
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   432
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   433
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   434
		return MessageFormat.format(Messages.getString("ConnectionStatusSelectorContribution.ConnectionStatusFormat"), defaultConnection.getDisplayName(), statusString); //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   435
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   436
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   437
	private String createStatusString(IConnectionStatus status) {
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   438
		String shortDescription = status.getShortDescription();
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   439
		if (shortDescription == null || shortDescription.length() == 0)
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   440
			return ""; //$NON-NLS-1$
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   441
		String pattern = Messages.getString("ConnectionStatusSelectorContribution.StatusFormat"); //$NON-NLS-1$
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   442
		if (shortDescription != null)
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   443
			shortDescription = shortDescription.toLowerCase();
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   444
		return MessageFormat.format(pattern, shortDescription, status.getLongDescription());
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   445
	}
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   446
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   447
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   448
	 * Get the image representing the connection status.
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   449
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   450
	 * @return Image, to be disposed
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   451
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   452
	private IConnectionStatus getConnectionStatus(IConnection connection) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   453
		if (!(connection instanceof IConnection2)) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   454
			return null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   455
		} else {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   456
			return ((IConnection2) connection).getStatus();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   457
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   458
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   459
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   460
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   461
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   462
	 */
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   463
	private void updateConnectionStatus(final IConnectionStatus status) {
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 724
diff changeset
   464
		Display.getDefault().asyncExec(new Runnable() {
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   465
			public void run() {
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   466
				if (connectionIcon == null || connectionIcon.isDisposed())
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   467
					return;
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   468
				
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   469
				Image statusImage;
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   470
				if (status != null)
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   471
					statusImage = ConnectionUIUtils.getConnectionStatusImage(status);
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   472
				else
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   473
					statusImage = ConnectionUIUtils.getConnectionImage(defaultConnection);
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   474
				
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   475
				connectionIcon.setImage(statusImage);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   476
				String tip = createConnectionStatusTooltip(defaultConnection, status);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   477
				connectionInfo.setToolTipText(tip);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   478
				
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 724
diff changeset
   479
				String preamble = Messages.getString("ConnectionStatusSelectorContribution.IconTooltipPrefixMessage"); //$NON-NLS-1$
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   480
				connectionIcon.setToolTipText(preamble + tip);		
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   481
			}
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   482
		});
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   483
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   484
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   485
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   486
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   487
	 * 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   488
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   489
	private void updateUI() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   490
		// perform update in UI thread
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   491
		final IWorkbench workbench = PlatformUI.getWorkbench();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   492
		workbench.getDisplay().asyncExec(new Runnable() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   493
			public void run() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   494
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   495
				if (window != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   496
					update();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   497
				}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   498
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   499
		});		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   500
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   501
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   502
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   503
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   504
	 * @see org.eclipse.jface.action.ContributionItem#isDynamic()
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   505
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   506
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   507
	public boolean isDynamic() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   508
		return true;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   509
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   510
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   511
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   512
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   513
	 * @see org.eclipse.jface.action.ContributionItem#update()
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   514
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   515
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   516
	public void update() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   517
		getParent().update(true);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   518
	}
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   519
	
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   520
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   521
	 * Show a status bubble for important changes.
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   522
	 * @param string
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   523
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   524
	public void launchBubble(final String string) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   525
		Display.getDefault().asyncExec(new Runnable() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   526
			public void run() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   527
				if (tooltip != null)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   528
					tooltip.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   529
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   530
				if (connectionInfo == null || connectionInfo.isDisposed())
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   531
					return;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   532
				
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   533
				tooltip = new ToolTip(connectionInfo.getParent().getShell(), SWT.BALLOON | SWT.ICON_INFORMATION);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   534
				tooltip.setMessage(string);
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   535
				Rectangle bounds = connectionInfo.getBounds();
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   536
				Point center = new Point(bounds.x + bounds.width / 2, 
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   537
						bounds.y + bounds.height);
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   538
				Point location = connectionInfo.getParent().toDisplay(center);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   539
				//System.out.println(connectionInfo.hashCode() + ": " + connectionInfo.getLocation() + " : " + location);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   540
				tooltip.setLocation(location);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   541
				tooltip.setVisible(true);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   542
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   543
		});
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   544
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   545
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   546
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   547
}