connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceStatusSelectorContribution.java
author Ed Swartz <ed.swartz@nokia.com>
Fri, 18 Dec 2009 09:34:05 -0600
changeset 706 bba29393db80
child 709 c92b05bdc957
permissions -rw-r--r--
Checkpoint commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
706
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     1
/*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     8
*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    11
*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    12
* Contributors:
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    13
*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    14
* Description: 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    15
*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    16
*/
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    17
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    18
package com.nokia.carbide.remoteconnections.internal.ui;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    19
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    20
import java.text.MessageFormat;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    21
import java.util.ArrayList;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    22
import java.util.Collections;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    23
import java.util.Comparator;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    24
import java.util.List;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    25
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    26
import org.eclipse.jface.layout.GridDataFactory;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    27
import org.eclipse.jface.layout.GridLayoutFactory;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    28
import org.eclipse.swt.SWT;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    29
import org.eclipse.swt.custom.CLabel;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    30
import org.eclipse.swt.events.MouseAdapter;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    31
import org.eclipse.swt.events.MouseEvent;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    32
import org.eclipse.swt.events.SelectionAdapter;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    33
import org.eclipse.swt.events.SelectionEvent;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    34
import org.eclipse.swt.graphics.Image;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    35
import org.eclipse.swt.graphics.Point;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    36
import org.eclipse.swt.widgets.Composite;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    37
import org.eclipse.swt.widgets.Control;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    38
import org.eclipse.swt.widgets.Display;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    39
import org.eclipse.swt.widgets.Menu;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    40
import org.eclipse.swt.widgets.MenuItem;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    41
import org.eclipse.swt.widgets.Shell;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    42
import org.eclipse.ui.IWorkbench;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    43
import org.eclipse.ui.IWorkbenchWindow;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    44
import org.eclipse.ui.PartInitException;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    45
import org.eclipse.ui.PlatformUI;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    46
import org.eclipse.ui.menus.WorkbenchWindowControlContribution;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    47
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    48
import com.nokia.carbide.remoteconnections.Messages;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    49
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    50
import com.nokia.carbide.remoteconnections.interfaces.IConnection;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    51
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    52
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    53
import com.nokia.carbide.remoteconnections.internal.api.IConnection2;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    54
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IStatus;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    55
import com.nokia.carbide.remoteconnections.internal.api.IConnection2.IStatusChangedListener;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    56
import com.nokia.carbide.remoteconnections.view.ConnectionsView;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    57
import com.nokia.cpp.internal.api.utils.core.TextUtils;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    58
import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    59
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    60
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    61
/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    62
 * This widget appears in the Eclipse trim and allows the user to select the
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    63
 * "default" device connection and also see its status at a glance. 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    64
 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    65
public class DeviceStatusSelectorContribution extends WorkbenchWindowControlContribution
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
		implements IConnectionListener, IStatusChangedListener {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    67
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    68
	private Composite container;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
	private CLabel deviceInfo;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
	private IConnectionsManager manager;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    71
	private Image deviceImage;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    72
	private IConnection defaultConnection;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    73
	
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    74
	public DeviceStatusSelectorContribution() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    75
		manager = RemoteConnectionsActivator.getConnectionsManager();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    76
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    77
	
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    78
	/*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    79
	 * (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    80
	 * @see org.eclipse.jface.action.ControlContribution#createControl(org.eclipse.swt.widgets.Composite)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    81
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    82
	@Override
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    83
	protected Control createControl(Composite parent) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    84
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    85
		// This UI is recreated whenever the default connection changes.
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    86
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    87
		manager.addConnectionListener(this);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    89
		container = new Composite(parent, SWT.NONE);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    90
		GridLayoutFactory.fillDefaults().margins(2, 0).applyTo(container);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    91
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    92
		// Create a label for the trim.
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    93
		deviceInfo = new CLabel(container, SWT.FLAT);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    94
		GridDataFactory.fillDefaults().grab(false, true).applyTo(deviceInfo);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    95
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    96
		String text = Messages.getString("DeviceStatusSelectorContribution_NoDefaultConnectionMessage"); //$NON-NLS-1$
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    97
		defaultConnection = manager.getDefaultConnection();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    98
		if (defaultConnection != null) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    99
			text = defaultConnection.getDisplayName();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   100
			if (defaultConnection instanceof IConnection2) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   101
				((IConnection2) defaultConnection).addStatusChangedListener(DeviceStatusSelectorContribution.this);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   102
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   103
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   104
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   105
		deviceInfo.setText(text);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   106
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   107
		updateDeviceStatus(getDeviceStatus(defaultConnection));
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   108
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   109
		deviceInfo.addMouseListener (new MouseAdapter() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   110
			public void mouseDown(MouseEvent event) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   111
				Shell shell = deviceInfo.getShell();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   112
				final Display display = shell.getDisplay();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   113
				
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   114
				final Menu menu = new Menu(shell, SWT.POP_UP);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   115
				populateConnectionMenu(menu);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   116
				
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   117
				Point screenLoc = deviceInfo.toDisplay(event.x, event.y);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   118
				menu.setLocation(screenLoc.x, screenLoc.y);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   119
				menu.setVisible(true);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   120
				
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   121
				while (!menu.isDisposed() && menu.isVisible()) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   122
					if (!display.readAndDispatch())
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   123
						display.sleep();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   124
				}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   125
				menu.dispose();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   126
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   127
			/* (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   128
			 * @see org.eclipse.swt.events.MouseAdapter#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   129
			 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   130
			@Override
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   131
			public void mouseDoubleClick(MouseEvent ev) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   132
				// NOTE: the menu usually comes up before double-click is seen
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   133
				if (ev.button == 1) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   134
					openConnectionsView();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   135
				}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   136
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   137
		});
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   138
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   139
		// TODO PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, null);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   140
		return container;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   141
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   142
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   143
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   144
	 * @param ev
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   145
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   146
	protected void openConnectionsView() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   147
		try {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   148
			WorkbenchUtils.getView(ConnectionsView.VIEW_ID);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   149
        } 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   150
        catch (PartInitException e) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   151
        	RemoteConnectionsActivator.logError(e);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   152
        }
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   153
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   154
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   155
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   156
	 * @param defaultConnection
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
	 * @param status
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   158
	 * @return
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   160
	private String createDeviceStatusTooltip(IConnection defaultConnection,
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   161
			IStatus status) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   162
		if (defaultConnection == null) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
			return Messages.getString("DeviceStatusSelectorContribution.NoDynamicOrManualConnectionsTooltip"); //$NON-NLS-1$
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   165
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   166
		String statusString = null;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   167
		if (status != null) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   168
			statusString = status.getDescription();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   169
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   170
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   171
		if (TextUtils.isEmpty(statusString))
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   172
			statusString = Messages.getString("DeviceStatusSelectorContribution.UnknownStatus"); //$NON-NLS-1$
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   173
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   174
		return MessageFormat.format(Messages.getString("DeviceStatusSelectorContribution.DeviceStatusFormat"), defaultConnection.getDisplayName(), statusString); //$NON-NLS-1$
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   175
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   176
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   177
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   178
	 * Get the image representing the device status.
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   179
	 * @param connection
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   180
	 * @return Image, to be disposed
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   181
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   182
	private IStatus getDeviceStatus(IConnection connection) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   183
		if (!(connection instanceof IConnection2)) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   184
			return null;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   185
		} else {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   186
			return ((IConnection2) connection).getStatus();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   187
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   188
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   189
	
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   190
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   191
	 * @return
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   192
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   193
	protected void populateConnectionMenu(Menu menu) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   194
		IConnection defaultConnection = manager.getDefaultConnection();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   195
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   196
		// Display the connections with dynamic ones first, 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   197
		// then static ones, separated by a separator
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   198
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   199
		List<IConnection> dynamicConnections = new ArrayList<IConnection>();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   200
		List<IConnection> staticConnections = new ArrayList<IConnection>();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   201
		for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   202
			if (connection instanceof IConnection2 && ((IConnection2)connection).isDynamic()) 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   203
				dynamicConnections.add(connection);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   204
			else
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   205
				staticConnections.add(connection);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   206
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   207
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   208
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   209
		Comparator<IConnection> connectionComparator = new Comparator<IConnection>() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   210
			public int compare(IConnection o1, IConnection o2) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   211
				return o1.getDisplayName().compareToIgnoreCase(o2.getDisplayName());
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   212
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   213
		};
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   214
		Collections.sort(dynamicConnections, connectionComparator);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   215
		Collections.sort(staticConnections, connectionComparator);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   216
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   217
		MenuItem label = new MenuItem(menu, SWT.NONE);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   218
		label.setEnabled(false);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   219
		label.setText(Messages.getString("DeviceStatusSelectorContribution_SelectTheDefaultConnectionMessage")); //$NON-NLS-1$
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   220
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   221
		for (IConnection connection : dynamicConnections) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   222
			createConnectionMenuItem(menu, connection, defaultConnection);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   223
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   224
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   225
		new MenuItem(menu, SWT.SEPARATOR);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   226
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   227
		for (IConnection connection : staticConnections) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   228
			createConnectionMenuItem(menu, connection, defaultConnection);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   229
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   230
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   231
		new MenuItem(menu, SWT.SEPARATOR);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   232
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   233
		MenuItem openView = new MenuItem(menu, SWT.PUSH);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   234
		openView.setText("Open Remote Connections view");
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   235
		openView.addSelectionListener(new SelectionAdapter() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   236
			@Override
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   237
			public void widgetSelected(SelectionEvent e) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   238
				openConnectionsView();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   239
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   240
		});
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   241
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   242
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   243
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   244
	 * @param menu
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   245
	 * @param connection
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   246
	 * @param defaultConnection 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   247
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   248
	private MenuItem createConnectionMenuItem(Menu menu, final IConnection connection, IConnection defaultConnection) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   249
		MenuItem item = new MenuItem(menu, SWT.CHECK);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   250
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   251
		boolean isDefault = false;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   252
		isDefault = connection.equals(defaultConnection);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   253
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   254
		item.setSelection(isDefault);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   255
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   256
		item.setText(connection.getDisplayName());
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   257
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   258
		item.addSelectionListener(new SelectionAdapter() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   259
			@Override
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   260
			public void widgetSelected(SelectionEvent e) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   261
				manager.setDefaultConnection(connection);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   262
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   263
		});		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   264
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   265
		return item;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   266
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   267
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   268
	/*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   269
	 * (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   270
	 * @see org.eclipse.jface.action.ContributionItem#dispose()
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   271
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   272
	public void dispose() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   273
		if (deviceImage != null) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   274
			deviceImage.dispose();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   275
			deviceImage = null;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   276
		}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   277
		if (defaultConnection instanceof IConnection2)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   278
			((IConnection2) defaultConnection).removeStatusChangedListener(this);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   279
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   280
		manager.removeConnectionListener(this);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   281
		super.dispose();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   282
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   283
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   284
	/* (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   285
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   286
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   287
	public void connectionAdded(IConnection connection) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   288
		updateUI();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   289
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   290
	
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   291
	/* (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   292
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   293
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   294
	public void connectionRemoved(IConnection connection) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   295
		updateUI();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   296
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   297
	/* (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   298
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#defaultConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   299
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   300
	public void defaultConnectionSet(IConnection connection) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   301
		updateUI();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   302
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   303
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   304
	/* (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   305
	 * @see com.nokia.carbide.remoteconnections.internal.IConnection2.IStatusChangedListener#statusChanged(com.nokia.carbide.remoteconnections.internal.IConnection2.IStatus)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   306
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   307
	public void statusChanged(IStatus status) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   308
		updateDeviceStatus(status);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   309
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   310
	
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   311
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   312
	 * @param status
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   313
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   314
	private void updateDeviceStatus(IStatus status) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   315
		if (deviceImage != null)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   316
			deviceImage.dispose();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   317
		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   318
		deviceImage = ConnectionUIUtils.getConnectionStatusImage(status);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   319
		deviceInfo.setImage(deviceImage);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   320
		deviceInfo.setToolTipText(createDeviceStatusTooltip(defaultConnection, status));
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   321
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   322
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   323
	/**
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   324
	 * 
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   325
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   326
	private void updateUI() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   327
		// perform update in UI thread
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   328
		final IWorkbench workbench = PlatformUI.getWorkbench();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   329
		workbench.getDisplay().asyncExec(new Runnable() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   330
			public void run() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   331
				IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   332
				if (window != null) {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   333
					update();
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   334
				}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   335
			}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   336
		});		
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   337
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   338
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   339
	/*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   340
	 * (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   341
	 * @see org.eclipse.jface.action.ContributionItem#isDynamic()
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   342
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   343
	@Override
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   344
	public boolean isDynamic() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   345
		return true;
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   346
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   347
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   348
	/*
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   349
	 * (non-Javadoc)
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   350
	 * @see org.eclipse.jface.action.ContributionItem#update()
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   351
	 */
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   352
	@Override
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   353
	public void update() {
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   354
		getParent().update(true);
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   355
	}
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   356
bba29393db80 Checkpoint commit
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   357
}