connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java
author Ed Swartz <ed.swartz@nokia.com>
Tue, 12 Jan 2010 09:39:44 -0600
changeset 757 dfe9c76b4eb2
parent 749 22f0d10fce10
child 761 19123c07e2ab
permissions -rw-r--r--
Select the default connection when opening the Remote Connections view from the selector widget.
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;
757
dfe9c76b4eb2 Select the default connection when opening the Remote Connections view from the selector widget.
Ed Swartz <ed.swartz@nokia.com>
parents: 749
diff changeset
    46
import org.eclipse.ui.IViewPart;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    47
import org.eclipse.ui.IWorkbench;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    48
import org.eclipse.ui.IWorkbenchWindow;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    49
import org.eclipse.ui.PartInitException;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    50
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
    51
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
    52
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
    53
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.Messages;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    55
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
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;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    58
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    59
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    60
import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    61
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IConnectionStatus;
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.IConnectionStatusChangedListener;
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.registry.Registry;
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.view.ConnectionsView;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    65
import com.nokia.cpp.internal.api.utils.core.TextUtils;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
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
    67
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    68
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
 * 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
    71
 * "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
    72
 * <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
    73
 * 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
    74
 * 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
    75
 * 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
    76
 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    77
@SuppressWarnings("deprecation")
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    78
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
    79
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
    80
	/**
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
    81
	 * 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
    82
	 * 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
    83
	 */
749
22f0d10fce10 Externalize strings
dadubrow
parents: 748
diff changeset
    84
	private static final String OPEN_REMOTE_CONNECTIONS_VIEW_COMMAND_ID = "openRemoteConnectionsView"; //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    85
	private Composite container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    86
	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
    87
	private ToolItem connectionIcon;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
	private IConnectionsManager manager;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    89
	private IConnection defaultConnection;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    90
	private ListenerBlock listenerBlock;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    91
	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
    92
	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
    93
	private ToolBar toolbar;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    94
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    95
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    96
	 * 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
    97
	 */
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
    98
	class ListenerBlock implements IConnectionListener, IConnectionsManagerListener, IConnectionStatusChangedListener {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    99
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   100
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   101
		 * @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
   102
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   103
		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
   104
			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
   105
			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
   106
			if (display)
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   107
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   108
						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
   109
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   110
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   111
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   112
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   113
		 * @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
   114
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   115
		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
   116
			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
   117
			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
   118
			if (display) 
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   119
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   120
						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
   121
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   122
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   123
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   124
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   125
		 * @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
   126
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   127
		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
   128
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   129
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   130
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   131
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   132
		 * @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
   133
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   134
		public void connectionStoreChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   135
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   136
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   137
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   138
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   139
		 * @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
   140
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   141
		public void displayChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   142
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   143
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   144
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   145
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   146
		 * @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
   147
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   148
		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
   149
			updateConnectionStatus(status);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   150
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   151
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   152
	}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   153
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   154
	public ConnectionStatusSelectorContribution() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   155
		manager = RemoteConnectionsActivator.getConnectionsManager();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   156
		listenerBlock = new ListenerBlock();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   158
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   160
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   161
	 * @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
   162
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
	protected Control createControl(Composite parent) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   165
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   166
		// 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
   167
		
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
   168
		// 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
   169
		// 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
   170
		// 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
   171
		// 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
   172
		//
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   173
		// 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
   174
		// 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
   175
		// 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
   176
		//
81b14a47b8dc Update UI 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
		// 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
   178
		// 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
   179
		// 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
   180
81b14a47b8dc Update UI 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
		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
   182
			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
   183
			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
   184
			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
   185
				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
   186
				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
   187
						((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
   188
					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
   189
					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
   190
				}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   191
			}
81b14a47b8dc Update UI 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
		} 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
   193
			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
   194
		}
81b14a47b8dc Update UI 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
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   196
		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
   197
		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
   198
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
   199
		// 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
   200
		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
   201
		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
   202
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   203
		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
   204
		defaultConnection = manager.getDefaultConnection();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   205
		if (defaultConnection != null)
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   206
			text = defaultConnection.getDisplayName();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   207
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   208
		connectionInfo.setText(text);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   209
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   210
		attachListeners();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   211
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   212
		updateConnectionStatus(getConnectionStatus(defaultConnection));
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   213
		
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
   214
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   215
		// 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
   216
		// 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
   217
			
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   218
		// 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
   219
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   220
		if (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
   221
			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
   222
				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
   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
			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
   225
				/* (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
   226
				 * @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
   227
				 */
81b14a47b8dc Update UI 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
				@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
   229
				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
   230
					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
   231
					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
   232
						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
   233
							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
   234
						} 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
   235
							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
   236
							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
   237
						}
81b14a47b8dc Update UI 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
					}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   239
				}
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
   240
			};
81b14a47b8dc Update UI 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
			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
   242
			
81b14a47b8dc Update UI 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
			// 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
   244
			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
   245
				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
   246
					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
   247
						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
   248
						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
   249
					}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   250
				}
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
   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
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   253
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   254
		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
   255
		return container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   256
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   257
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
   258
	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
   259
		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
   260
		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
   261
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   262
		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
   263
		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
   264
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   265
		menu.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
   266
		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
   267
		
81b14a47b8dc Update UI 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
		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
   269
			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
   270
				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
   271
		}
81b14a47b8dc Update UI 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
		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
   273
	
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   274
	}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   275
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   276
	/**
81b14a47b8dc Update UI 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
	 * @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
   278
	 */
81b14a47b8dc Update UI 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
	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
   280
		// 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
   281
		// 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
   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
		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
   284
		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
   285
		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
   286
			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
   287
				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
   288
			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
   289
				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
   290
		}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   291
		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   292
	
81b14a47b8dc Update UI 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
		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
   294
			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
   295
				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
   296
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   297
		};
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   298
		Collections.sort(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
   299
		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
   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
		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
   302
		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
   303
		
81b14a47b8dc Update UI 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
		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
   305
		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
   306
			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
   307
		} 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
   308
			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
   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
			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
   311
				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
   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
			
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   314
			if (!staticConnections.isEmpty())
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   315
				new MenuItem(menu, SWT.SEPARATOR);
723
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   316
			
81b14a47b8dc Update UI 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
			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
   318
				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
   319
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   320
		}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   321
		
81b14a47b8dc Update UI 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
		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
   323
		
81b14a47b8dc Update UI 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
		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
   325
		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
   326
		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
   327
			@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
   328
			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
   329
				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
   330
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   331
		});
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   332
	}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   333
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   334
	/**
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   335
	 * @param 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
   336
	 * @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
   337
	 * @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
   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
	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
   340
			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
   341
			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
   342
			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
   343
		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
   344
		
81b14a47b8dc Update UI 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
		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
   346
		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
   347
		
81b14a47b8dc Update UI 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
		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
   349
		
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
   350
		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
   351
		
81b14a47b8dc Update UI 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
		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
   353
			@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
   354
			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
   355
				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
   356
			}
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   357
		});		
81b14a47b8dc Update UI for Remote Connections status widget and News Reader to behave the same (bug #10411)
Ed Swartz <ed.swartz@nokia.com>
parents: 721
diff changeset
   358
		
81b14a47b8dc Update UI 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
		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
   360
	}
81b14a47b8dc Update UI 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
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   362
	private void attachListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   363
		manager.addConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   364
		Registry.instance().addConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   365
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   366
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   367
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   368
				((IConnection2) defaultConnection).addStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   369
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   370
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   371
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   372
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   373
	private void removeListeners() {
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).removeStatusChangedListener(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
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   379
		manager.removeConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   380
		Registry.instance().removeConnectionStoreChangedListener(listenerBlock);
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
	 * (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   385
	 * @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
   386
	 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   387
	public void dispose() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   388
		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
   389
		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
   390
			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
   391
		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
   392
			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
   393
		if (connectionInfo != null)
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   394
			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
   395
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   396
		super.dispose();
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
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   399
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   400
	 * @param ev
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   401
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   402
	protected void openConnectionsView() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   403
		try {
757
dfe9c76b4eb2 Select the default connection when opening the Remote Connections view from the selector widget.
Ed Swartz <ed.swartz@nokia.com>
parents: 749
diff changeset
   404
			IViewPart view = WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
dfe9c76b4eb2 Select the default connection when opening the Remote Connections view from the selector widget.
Ed Swartz <ed.swartz@nokia.com>
parents: 749
diff changeset
   405
			if (defaultConnection != null && view instanceof ConnectionsView) {
dfe9c76b4eb2 Select the default connection when opening the Remote Connections view from the selector widget.
Ed Swartz <ed.swartz@nokia.com>
parents: 749
diff changeset
   406
				((ConnectionsView) view).setSelectedConnection(defaultConnection);
dfe9c76b4eb2 Select the default connection when opening the Remote Connections view from the selector widget.
Ed Swartz <ed.swartz@nokia.com>
parents: 749
diff changeset
   407
			}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   408
        } 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   409
        catch (PartInitException e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   410
        	RemoteConnectionsActivator.logError(e);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   411
        }
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   412
	}
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
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   415
	 * @param defaultConnection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   416
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
	 * @return
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   418
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   419
	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
   420
			IConnectionStatus status) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   421
		if (defaultConnection == null) {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   422
			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
   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
		String statusString = null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   426
		if (status != null) {
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   427
			statusString = createStatusString(status);
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   428
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   429
		
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
   430
		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
   431
			// 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
   432
			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
   433
				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
   434
			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
   435
				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
   436
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   437
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   438
		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
   439
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   440
748
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   441
	private String createStatusString(IConnectionStatus status) {
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   442
		String shortDescription = status.getShortDescription();
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   443
		if (shortDescription == null || shortDescription.length() == 0)
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   444
			return ""; //$NON-NLS-1$
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   445
		String pattern = Messages.getString("ConnectionStatusSelectorContribution.StatusFormat"); //$NON-NLS-1$
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   446
		if (shortDescription != null)
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   447
			shortDescription = shortDescription.toLowerCase();
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   448
		return MessageFormat.format(pattern, shortDescription, status.getLongDescription());
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   449
	}
7bd40a2d0a18 Add connection status reconciliation + fixes + tweaks
dadubrow
parents: 730
diff changeset
   450
710
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
	 * 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
   453
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   454
	 * @return Image, to be disposed
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   455
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   456
	private IConnectionStatus getConnectionStatus(IConnection connection) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   457
		if (!(connection instanceof IConnection2)) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   458
			return null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   459
		} else {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   460
			return ((IConnection2) connection).getStatus();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   461
		}
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
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   466
	 */
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   467
	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
   468
		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
   469
			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
   470
				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
   471
					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
   472
				
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
				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
   474
				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
   475
					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
   476
				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
   477
					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
   478
				
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
   479
				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
   480
				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
   481
				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
   482
				
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
   483
				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
   484
				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
   485
			}
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
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   488
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   489
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
	private void updateUI() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   494
		// perform update in UI thread
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   495
		final IWorkbench workbench = PlatformUI.getWorkbench();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   496
		workbench.getDisplay().asyncExec(new Runnable() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   497
			public void run() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   498
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   499
				if (window != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   500
					update();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   501
				}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   502
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   503
		});		
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
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   508
	 * @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
   509
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   510
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   511
	public boolean isDynamic() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   512
		return true;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   513
	}
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
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   517
	 * @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
   518
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   519
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   520
	public void update() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   521
		getParent().update(true);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   522
	}
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   523
	
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
	 * 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
   526
	 * @param string
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   527
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   528
	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
   529
		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
   530
			public void run() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   531
				if (tooltip != null)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   532
					tooltip.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   533
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   534
				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
   535
					return;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   536
				
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
   537
				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
   538
				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
   539
				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
   540
				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
   541
						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
   542
				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
   543
				//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
   544
				tooltip.setLocation(location);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   545
				tooltip.setVisible(true);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   546
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   547
		});
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   548
	}
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
}