connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java
author Ed Swartz <ed.swartz@nokia.com>
Wed, 30 Dec 2009 11:43:43 -0600
changeset 730 8ecd45ef360e
parent 724 6ab9c30e708f
child 748 7bd40a2d0a18
permissions -rw-r--r--
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.
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;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    55
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
710
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.IConnection;
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;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    58
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    59
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
710
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.interfaces.IConnectionsManager.IConnectionListener;
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.interfaces.IConnectionsManager.IConnectionsManagerListener;
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.api.IConnection2;
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.internal.api.IConnection2.IConnectionStatus;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    64
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
    65
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
    66
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
    67
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
    68
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
    69
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    71
/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    72
 * 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
    73
 * "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
    74
 * <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
    75
 * 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
    76
 * 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
    77
 * 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
    78
 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    79
@SuppressWarnings("deprecation")
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    80
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
    81
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
    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
	 * 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
    84
	 * 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
    85
	 */
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
    86
	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
    87
	private Composite container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
	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
    89
	private ToolItem connectionIcon;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    90
	private IConnectionsManager manager;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    91
	private IConnection defaultConnection;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    92
	private ListenerBlock listenerBlock;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    93
	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
    94
	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
    95
	private ToolBar toolbar;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    96
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    97
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    98
	 * 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
    99
	 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   100
	class ListenerBlock implements IConnectionListener, IConnectionsManagerListener, IStatusChangedListener, IConnectionStatusChangedListener {
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
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   103
		 * @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
   104
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   105
		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
   106
			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
   107
			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
   108
			if (display)
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   109
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   110
						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
   111
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   112
		}
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
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   115
		 * @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
   116
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   117
		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
   118
			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
   119
			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
   120
			if (display) 
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   121
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   122
						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
   123
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   124
		}
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
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   127
		 * @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
   128
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   129
		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
   130
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   131
		}
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
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   134
		 * @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
   135
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   136
		public void connectionStoreChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   137
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   138
		}
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
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   141
		 * @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
   142
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   143
		public void displayChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   144
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   145
		}
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
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   148
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener#statusChanged(com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus)
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
		public void statusChanged(IStatus status) {
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
   151
			updateConnectionStatus(null);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   152
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   153
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   154
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   155
		 * @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
   156
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   157
		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
   158
			updateConnectionStatus(status);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   159
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   160
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   161
	}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   162
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
	public ConnectionStatusSelectorContribution() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
		manager = RemoteConnectionsActivator.getConnectionsManager();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   165
		listenerBlock = new ListenerBlock();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   166
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   167
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   168
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   169
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   170
	 * @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
   171
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   172
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   173
	protected Control createControl(Composite parent) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   174
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   175
		// 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
   176
		
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
   177
		// 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
   178
		// 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
   179
		// 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
   180
		// 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
   181
		//
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
		// 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
   183
		// 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
   184
		// 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
   185
		//
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
   186
		// 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
   187
		// 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
   188
		// 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
   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
		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
   191
			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
   192
			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
   193
			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
   194
				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
   195
				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
   196
						((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
   197
					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
   198
					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
   199
				}
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
   200
			}
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
   201
		} 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
   202
			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
   203
		}
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
   204
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   205
		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
   206
		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
   207
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
   208
		// 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
   209
		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
   210
		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
   211
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   212
		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
   213
		defaultConnection = manager.getDefaultConnection();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   214
		if (defaultConnection != null)
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   215
			text = defaultConnection.getDisplayName();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   216
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   217
		connectionInfo.setText(text);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   218
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   219
		attachListeners();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   220
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   221
		updateConnectionStatus(getConnectionStatus(defaultConnection));
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   222
		
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
   223
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
		// 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
   225
		// 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
   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
		// 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
   228
		
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
		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
   230
			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
   231
				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
   232
			
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
			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
   234
				/* (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
   235
				 * @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
   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
				@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
   238
				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
   239
					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
   240
					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
   241
						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
   242
							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
   243
						} 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
   244
							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
   245
							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
   246
						}
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
					}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   248
				}
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
   249
			};
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
			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
   251
			
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
   252
			// 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
   253
			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
   254
				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
   255
					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
   256
						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
   257
						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
   258
					}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   259
				}
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
   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
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   262
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   263
		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
   264
		return container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   265
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   266
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
   267
	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
   268
		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
   269
		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
   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
		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
   272
		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
   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
		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
   275
		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
   276
		
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
		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
   278
			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
   279
				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
   280
		}
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
		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
   282
	
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
	}
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
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
	/**
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
	 * @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
   287
	 */
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
	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
   289
		// 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
   290
		// 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
   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
		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
   293
		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
   294
		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
   295
			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
   296
				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
   297
			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
   298
				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
   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
		
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
	
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
		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
   303
			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
   304
				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
   305
			}
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
		};
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
		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
   308
		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
   309
	
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
		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
   311
		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
   312
		
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
   313
		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
   314
		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
   315
			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
   316
		} 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
   317
			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
   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
			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
   320
				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
   321
			}
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
			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
   324
			
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
			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
   326
				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
   327
			}
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
		}
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
		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
   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
		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
   333
		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
   334
		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
   335
			@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
   336
			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
   337
				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
   338
			}
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
		});
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
	}
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
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
	/**
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
	 * @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
   344
	 * @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
   345
	 * @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
   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
	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
   348
			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
   349
			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
   350
			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
   351
		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
   352
		
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
		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
   354
		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
   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
		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
   357
		
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
   358
		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
   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
		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
   361
			@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
   362
			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
   363
				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
   364
			}
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
   365
		});		
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
   366
		
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
   367
		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
   368
	}
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
   369
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   370
	private void attachListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   371
		manager.addConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   372
		Registry.instance().addConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   373
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   374
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   375
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   376
				((IConnection2) defaultConnection).addStatusChangedListener(listenerBlock);
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
			for (IConnectedService service : manager.getConnectedServices(defaultConnection)) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   379
				service.addStatusChangedListener(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
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   384
	private void removeListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   385
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   386
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   387
				((IConnection2) defaultConnection).removeStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   388
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   389
			for (IConnectedService service : manager.getConnectedServices(defaultConnection)) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   390
				service.removeStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   391
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   392
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   393
		manager.removeConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   394
		Registry.instance().removeConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   395
	}
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
	/*
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   398
	 * (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   399
	 * @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
   400
	 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   401
	public void dispose() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   402
		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
   403
		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
   404
			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
   405
		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
   406
			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
   407
		if (connectionInfo != null)
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   408
			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
   409
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   410
		super.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   411
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   412
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   413
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   414
	 * @param ev
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   415
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   416
	protected void openConnectionsView() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
		try {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   418
			WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
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
        catch (PartInitException e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   421
        	RemoteConnectionsActivator.logError(e);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   422
        }
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   423
	}
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
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   426
	 * @param defaultConnection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   427
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   428
	 * @return
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   429
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   430
	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
   431
			IConnectionStatus status) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   432
		if (defaultConnection == null) {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   433
			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
   434
		}
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
		String statusString = null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   437
		if (status != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   438
			statusString = status.getDescription();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   439
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   440
		
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
   441
		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
   442
			// 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
   443
			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
   444
				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
   445
			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
   446
				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
   447
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   448
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   449
		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
   450
	}
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
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   453
	 * 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
   454
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   455
	 * @return Image, to be disposed
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   456
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   457
	private IConnectionStatus getConnectionStatus(IConnection connection) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   458
		if (!(connection instanceof IConnection2)) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   459
			return null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   460
		} else {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   461
			return ((IConnection2) connection).getStatus();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   462
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   463
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   464
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   465
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   466
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   467
	 */
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
   468
	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
   469
		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
   470
			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
   471
				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
   472
					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
   473
				
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
				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
   475
				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
   476
					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
   477
				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
   478
					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
   479
				
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.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
   481
				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
   482
				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
   483
				
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
   484
				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
   485
				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
   486
			}
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
   487
		});
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
   488
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   489
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   490
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   491
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   492
	 * 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   493
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   494
	private void updateUI() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   495
		// perform update in UI thread
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   496
		final IWorkbench workbench = PlatformUI.getWorkbench();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   497
		workbench.getDisplay().asyncExec(new Runnable() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   498
			public void run() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   499
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   500
				if (window != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   501
					update();
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
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   504
		});		
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
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   507
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   508
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   509
	 * @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
   510
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   511
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   512
	public boolean isDynamic() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   513
		return true;
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
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   516
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   517
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   518
	 * @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
   519
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   520
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   521
	public void update() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   522
		getParent().update(true);
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
	
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   525
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   526
	 * 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
   527
	 * @param string
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   528
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   529
	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
   530
		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
   531
			public void run() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   532
				if (tooltip != null)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   533
					tooltip.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   534
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   535
				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
   536
					return;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   537
				
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
   538
				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
   539
				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
   540
				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
   541
				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
   542
						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
   543
				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
   544
				//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
   545
				tooltip.setLocation(location);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   546
				tooltip.setVisible(true);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   547
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   548
		});
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   549
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   550
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   551
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   552
}