connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ConnectionStatusSelectorContribution.java
author Ed Swartz <ed.swartz@nokia.com>
Fri, 18 Dec 2009 15:05:20 -0600
changeset 721 dbd80b3d41cc
parent 714 eeeba49ae3f1
child 723 81b14a47b8dc
permissions -rw-r--r--
Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
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;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    36
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
    37
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
    38
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
    39
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
    40
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
    41
import org.eclipse.swt.widgets.Shell;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    42
import org.eclipse.swt.widgets.ToolTip;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    43
import org.eclipse.ui.IWorkbench;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    44
import org.eclipse.ui.IWorkbenchWindow;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    45
import org.eclipse.ui.PartInitException;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    46
import org.eclipse.ui.PlatformUI;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    47
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
    48
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    49
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
    50
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    51
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    52
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
    53
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    54
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    55
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    56
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
    57
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
    58
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
    59
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
    60
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
    61
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
    62
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
    63
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
    64
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
    65
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    67
/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    68
 * This widget appears in the Eclipse trim and allows the user to select the
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
 * "default" device connection and also see its status at a glance. 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    71
@SuppressWarnings("deprecation")
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    72
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
    73
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    74
	private Composite container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    75
	private CLabel connectionInfo;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    76
	private IConnectionsManager manager;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    77
	private IConnection defaultConnection;
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    78
	private ListenerBlock listenerBlock;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    79
	private ToolTip tooltip;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    80
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    81
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    82
	 * 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
    83
	 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    84
	class ListenerBlock implements IConnectionListener, IConnectionsManagerListener, IStatusChangedListener, IConnectionStatusChangedListener {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    85
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    86
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    87
		 * @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
    88
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    89
		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
    90
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    91
			if (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic())
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    92
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    93
						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
    94
						connection.getDisplayName()));
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
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    97
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
    98
		 * @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
    99
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   100
		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
   101
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   102
			if (connection instanceof IConnection2 && ((IConnection2) connection).isDynamic())
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   103
				launchBubble(MessageFormat.format(
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   104
						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
   105
						connection.getDisplayName()));
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   106
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   107
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   108
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   109
		 * @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
   110
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   111
		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
   112
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   113
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   114
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   115
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   116
		 * @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
   117
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   118
		public void connectionStoreChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   119
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   120
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   121
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   122
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   123
		 * @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
   124
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   125
		public void displayChanged() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   126
			updateUI();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   127
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   128
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   129
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   130
		 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener#statusChanged(com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   131
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   132
		public void statusChanged(IStatus status) {
721
dbd80b3d41cc Show in-use/not-in-use connection status icon, until real IConnectedStatus is available.
Ed Swartz <ed.swartz@nokia.com>
parents: 714
diff changeset
   133
			updateConnectionStatus(null);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   134
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   135
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   136
		/* (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   137
		 * @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
   138
		 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   139
		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
   140
			updateConnectionStatus(status);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   141
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   142
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   143
	}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   144
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   145
	public ConnectionStatusSelectorContribution() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   146
		manager = RemoteConnectionsActivator.getConnectionsManager();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   147
		listenerBlock = new ListenerBlock();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   148
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   149
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   150
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   151
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   152
	 * @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
   153
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   154
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   155
	protected Control createControl(Composite parent) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   156
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
		// 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
   158
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
		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
   160
		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
   161
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   162
		// Create a label for the trim.
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
		connectionInfo = new CLabel(container, SWT.FLAT);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
		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
   165
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   166
		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
   167
		defaultConnection = manager.getDefaultConnection();
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   168
		if (defaultConnection != null)
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   169
			text = defaultConnection.getDisplayName();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   170
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   171
		connectionInfo.setText(text);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   172
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   173
		attachListeners();
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   174
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   175
		updateConnectionStatus(getConnectionStatus(defaultConnection));
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   176
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   177
		connectionInfo.addMouseListener (new MouseAdapter() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   178
			public void mouseDown(MouseEvent event) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   179
				Shell shell = connectionInfo.getShell();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   180
				final Display display = shell.getDisplay();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   181
				
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   182
				final Menu menu = new Menu(shell, SWT.POP_UP);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   183
				populateConnectionMenu(menu);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   184
				
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   185
				Point screenLoc = connectionInfo.toDisplay(event.x, event.y);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   186
				menu.setLocation(screenLoc.x, screenLoc.y);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   187
				menu.setVisible(true);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   188
				
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   189
				while (!menu.isDisposed() && menu.isVisible()) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   190
					if (!display.readAndDispatch())
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   191
						display.sleep();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   192
				}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   193
				menu.dispose();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   194
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   195
			/* (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   196
			 * @see org.eclipse.swt.events.MouseAdapter#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   197
			 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   198
			@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   199
			public void mouseDoubleClick(MouseEvent ev) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   200
				// NOTE: the menu usually comes up before double-click is seen
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   201
				if (ev.button == 1) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   202
					openConnectionsView();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   203
				}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   204
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   205
		});
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   206
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   207
		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
   208
		return container;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   209
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   210
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   211
	private void attachListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   212
		manager.addConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   213
		Registry.instance().addConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   214
		
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   215
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   216
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   217
				((IConnection2) defaultConnection).addStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   218
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   219
			for (IConnectedService service : manager.getConnectedServices(defaultConnection)) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   220
				service.addStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   221
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   222
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   223
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   224
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   225
	private void removeListeners() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   226
		if (defaultConnection != null) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   227
			if (defaultConnection instanceof IConnection2) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   228
				((IConnection2) defaultConnection).removeStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   229
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   230
			for (IConnectedService service : manager.getConnectedServices(defaultConnection)) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   231
				service.removeStatusChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   232
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   233
		}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   234
		manager.removeConnectionListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   235
		Registry.instance().removeConnectionStoreChangedListener(listenerBlock);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   236
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   237
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   238
	/*
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   239
	 * (non-Javadoc)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   240
	 * @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
   241
	 */
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   242
	public void dispose() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   243
		removeListeners();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   244
		if (connectionInfo != null)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   245
			connectionInfo.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   246
		super.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   247
	}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   248
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   249
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   250
	 * @param ev
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   251
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   252
	protected void openConnectionsView() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   253
		try {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   254
			WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   255
        } 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   256
        catch (PartInitException e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   257
        	RemoteConnectionsActivator.logError(e);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   258
        }
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   259
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   260
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   261
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   262
	 * @param defaultConnection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   263
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   264
	 * @return
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   265
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   266
	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
   267
			IConnectionStatus status) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   268
		if (defaultConnection == null) {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   269
			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
   270
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   271
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   272
		String statusString = null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   273
		if (status != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   274
			statusString = status.getDescription();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   275
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   276
		
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
   277
		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
   278
			// 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
   279
			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
   280
				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
   281
			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
   282
				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
   283
		}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   284
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   285
		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
   286
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   287
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   288
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   289
	 * 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
   290
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   291
	 * @return Image, to be disposed
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   292
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   293
	private IConnectionStatus getConnectionStatus(IConnection connection) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   294
		if (!(connection instanceof IConnection2)) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   295
			return null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   296
		} else {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   297
			return ((IConnection2) connection).getStatus();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   298
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   299
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   300
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   301
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   302
	 * @return
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   303
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   304
	protected void populateConnectionMenu(Menu menu) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   305
		// Display the connections with dynamic ones first, 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   306
		// then static ones, separated by a separator
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   307
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   308
		List<IConnection> dynamicConnections = new ArrayList<IConnection>();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   309
		List<IConnection> staticConnections = new ArrayList<IConnection>();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   310
		for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   311
			if (connection instanceof IConnection2 && ((IConnection2)connection).isDynamic()) 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   312
				dynamicConnections.add(connection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   313
			else
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   314
				staticConnections.add(connection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   315
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   316
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   317
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   318
		Comparator<IConnection> connectionComparator = new Comparator<IConnection>() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   319
			public int compare(IConnection o1, IConnection o2) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   320
				return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   321
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   322
		};
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   323
		Collections.sort(dynamicConnections, connectionComparator);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   324
		Collections.sort(staticConnections, connectionComparator);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   325
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   326
		MenuItem label = new MenuItem(menu, SWT.NONE);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   327
		label.setEnabled(false);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   328
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   329
		if (dynamicConnections.size() + staticConnections.size() == 0) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   330
			label.setText(Messages.getString("ConnectionStatusSelectorContribution.NoConnectionsDefinedOrDetected")); //$NON-NLS-1$
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   331
		} else {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   332
			label.setText(Messages.getString("ConnectionStatusSelectorContribution_SelectTheDefaultConnectionMessage")); //$NON-NLS-1$
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   333
			
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   334
			for (IConnection connection : dynamicConnections) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   335
				createConnectionMenuItem(menu, connection, defaultConnection);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   336
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   337
			
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   338
			new MenuItem(menu, SWT.SEPARATOR);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   339
			
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   340
			for (IConnection connection : staticConnections) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   341
				createConnectionMenuItem(menu, connection, defaultConnection);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   342
			}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   343
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   344
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   345
		new MenuItem(menu, SWT.SEPARATOR);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   346
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   347
		MenuItem openView = new MenuItem(menu, SWT.PUSH);
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   348
		openView.setText(Messages.getString("ConnectionStatusSelectorContribution.OpenRemoteConnectionsView")); //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   349
		openView.addSelectionListener(new SelectionAdapter() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   350
			@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   351
			public void widgetSelected(SelectionEvent e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   352
				openConnectionsView();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   353
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   354
		});
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   355
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   356
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   357
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   358
	 * @param menu
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   359
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   360
	 * @param defaultConnection 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   361
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   362
	private MenuItem createConnectionMenuItem(Menu menu, final IConnection connection, IConnection defaultConnection) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   363
		MenuItem item = new MenuItem(menu, SWT.CHECK);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   364
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   365
		boolean isDefault = false;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   366
		isDefault = connection.equals(defaultConnection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   367
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   368
		item.setSelection(isDefault);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   369
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   370
		item.setText(connection.getDisplayName());
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   371
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   372
		item.addSelectionListener(new SelectionAdapter() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   373
			@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   374
			public void widgetSelected(SelectionEvent e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   375
				manager.setDefaultConnection(connection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   376
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   377
		});		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   378
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   379
		return item;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   380
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   381
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   382
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   383
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   384
	 */
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
   385
	private void updateConnectionStatus(final IConnectionStatus 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
   386
		Display.getDefault().syncExec(new Runnable() {
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
   387
			public void run() {
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
   388
				if (connectionInfo.isDisposed())
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
   389
					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
   390
				
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
   391
				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
   392
				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
   393
					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
   394
				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
   395
					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
   396
				
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
   397
				connectionInfo.setImage(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
   398
				connectionInfo.setToolTipText(createConnectionStatusTooltip(defaultConnection, 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
   399
			}
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
   400
		});
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
   401
		
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   402
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   403
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   404
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   405
	 * 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   406
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   407
	private void updateUI() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   408
		// perform update in UI thread
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   409
		final IWorkbench workbench = PlatformUI.getWorkbench();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   410
		workbench.getDisplay().asyncExec(new Runnable() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   411
			public void run() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   412
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   413
				if (window != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   414
					update();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   415
				}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   416
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
		});		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   418
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   419
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   420
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   421
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   422
	 * @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
   423
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   424
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   425
	public boolean isDynamic() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   426
		return true;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   427
	}
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
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   430
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   431
	 * @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
   432
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   433
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   434
	public void update() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   435
		getParent().update(true);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   436
	}
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   437
	
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   438
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   439
	 * 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
   440
	 * @param string
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   441
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   442
	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
   443
		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
   444
			public void run() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   445
				if (tooltip != null)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   446
					tooltip.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   447
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   448
				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
   449
					return;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   450
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   451
				tooltip = new ToolTip(connectionInfo.getShell(), SWT.BALLOON | SWT.ICON_INFORMATION);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   452
				tooltip.setMessage(string);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   453
				Point center = connectionInfo.getSize();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   454
				center.x /= 2;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   455
				Point location = connectionInfo.toDisplay(center);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   456
				//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
   457
				tooltip.setLocation(location);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   458
				tooltip.setVisible(true);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   459
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   460
		});
710
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
}