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 11:48:15 -0600
changeset 714 eeeba49ae3f1
parent 710 47bb893ba749
child 721 dbd80b3d41cc
permissions -rw-r--r--
Add bubble popup when dynamic connection added or removed
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) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   133
			updateUI();
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
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   277
		if (TextUtils.isEmpty(statusString))
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   278
			statusString = Messages.getString("ConnectionStatusSelectorContribution.NotInUse"); //$NON-NLS-1$
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   279
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   280
		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
   281
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   282
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   283
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   284
	 * 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
   285
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   286
	 * @return Image, to be disposed
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
	private IConnectionStatus getConnectionStatus(IConnection connection) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   289
		if (!(connection instanceof IConnection2)) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   290
			return null;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   291
		} else {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   292
			return ((IConnection2) connection).getStatus();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   293
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   294
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   295
	
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   296
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   297
	 * @return
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
	protected void populateConnectionMenu(Menu menu) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   300
		// 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
   301
		// 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
   302
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   303
		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
   304
		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
   305
		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
   306
			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
   307
				dynamicConnections.add(connection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   308
			else
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   309
				staticConnections.add(connection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   310
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   311
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   312
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   313
		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
   314
			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
   315
				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
   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
		Collections.sort(dynamicConnections, connectionComparator);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   319
		Collections.sort(staticConnections, connectionComparator);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   320
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   321
		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
   322
		label.setEnabled(false);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   323
		
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   324
		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
   325
			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
   326
		} else {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   327
			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
   328
			
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   329
			for (IConnection connection : dynamicConnections) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   330
				createConnectionMenuItem(menu, connection, defaultConnection);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   331
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   332
			
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   333
			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
   334
			
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   335
			for (IConnection connection : staticConnections) {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   336
				createConnectionMenuItem(menu, connection, defaultConnection);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   337
			}
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   338
		}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   339
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   340
		new MenuItem(menu, SWT.SEPARATOR);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   341
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   342
		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
   343
		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
   344
		openView.addSelectionListener(new SelectionAdapter() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   345
			@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   346
			public void widgetSelected(SelectionEvent e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   347
				openConnectionsView();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   348
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   349
		});
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   350
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   351
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   352
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   353
	 * @param menu
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   354
	 * @param connection
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   355
	 * @param defaultConnection 
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
	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
   358
		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
   359
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   360
		boolean isDefault = false;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   361
		isDefault = connection.equals(defaultConnection);
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   362
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   363
		item.setSelection(isDefault);
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
		item.setText(connection.getDisplayName());
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   366
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   367
		item.addSelectionListener(new SelectionAdapter() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   368
			@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   369
			public void widgetSelected(SelectionEvent e) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   370
				manager.setDefaultConnection(connection);
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
		});		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   373
		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   374
		return item;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   375
	}
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
	 * @param status
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   379
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   380
	private void updateConnectionStatus(IConnectionStatus status) {
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   381
		Image statusImage = ConnectionUIUtils.getConnectionStatusImage(status);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   382
		connectionInfo.setImage(statusImage);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   383
		connectionInfo.setToolTipText(createConnectionStatusTooltip(defaultConnection, status));
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   384
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   385
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   386
	/**
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   387
	 * 
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   388
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   389
	private void updateUI() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   390
		// perform update in UI thread
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   391
		final IWorkbench workbench = PlatformUI.getWorkbench();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   392
		workbench.getDisplay().asyncExec(new Runnable() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   393
			public void run() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   394
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   395
				if (window != null) {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   396
					update();
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   397
				}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   398
			}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   399
		});		
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   400
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   401
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
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   404
	 * @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
   405
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   406
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   407
	public boolean isDynamic() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   408
		return true;
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   409
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   410
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   411
	/*
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   412
	 * (non-Javadoc)
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   413
	 * @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
   414
	 */
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   415
	@Override
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   416
	public void update() {
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
		getParent().update(true);
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
	
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   420
	/**
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   421
	 * 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
   422
	 * @param string
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   423
	 */
714
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   424
	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
   425
		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
   426
			public void run() {
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   427
				if (tooltip != null)
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   428
					tooltip.dispose();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   429
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   430
				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
   431
					return;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   432
				
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   433
				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
   434
				tooltip.setMessage(string);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   435
				Point center = connectionInfo.getSize();
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   436
				center.x /= 2;
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   437
				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
   438
				//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
   439
				tooltip.setLocation(location);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   440
				tooltip.setVisible(true);
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   441
			}
eeeba49ae3f1 Add bubble popup when dynamic connection added or removed
Ed Swartz <ed.swartz@nokia.com>
parents: 710
diff changeset
   442
		});
710
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   443
	}
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   444
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   445
47bb893ba749 Attach listener to connection name changes, rename Device -> Connection
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   446
}