debuggercdi/com.nokia.cdt.debug.launch/src/com/nokia/cdt/internal/debug/launch/newwizard/ConnectToDeviceDialog.java
author dadubrow
Mon, 15 Feb 2010 13:49:01 -0600
changeset 956 d1e221a2875f
child 964 b0c1a1239188
permissions -rw-r--r--
new launch wizard implementation
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
956
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     1
/*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     2
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     3
* All rights reserved.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     4
* This component and the accompanying materials are made available
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     6
* which accompanies this distribution, and is available
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     8
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
     9
* Initial Contributors:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    11
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    12
* Contributors:
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    13
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    14
* Description: 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    15
*
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    16
*/
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    17
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    18
package com.nokia.cdt.internal.debug.launch.newwizard;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    19
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    20
import java.text.MessageFormat;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    21
import java.util.ArrayList;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    22
import java.util.Collection;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    23
import java.util.HashSet;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    24
import java.util.List;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    25
import java.util.Set;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    26
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    27
import org.eclipse.core.runtime.IStatus;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    28
import org.eclipse.jface.layout.GridDataFactory;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    29
import org.eclipse.jface.layout.GridLayoutFactory;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    30
import org.eclipse.jface.viewers.ArrayContentProvider;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    31
import org.eclipse.jface.viewers.ComboViewer;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    32
import org.eclipse.jface.viewers.ISelection;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    33
import org.eclipse.jface.viewers.ISelectionChangedListener;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    34
import org.eclipse.jface.viewers.IStructuredSelection;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    35
import org.eclipse.jface.viewers.LabelProvider;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    36
import org.eclipse.jface.viewers.SelectionChangedEvent;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    37
import org.eclipse.jface.viewers.StructuredSelection;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    38
import org.eclipse.swt.SWT;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    39
import org.eclipse.swt.events.ControlAdapter;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    40
import org.eclipse.swt.events.ControlEvent;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    41
import org.eclipse.swt.events.SelectionAdapter;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    42
import org.eclipse.swt.events.SelectionEvent;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    43
import org.eclipse.swt.widgets.Button;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    44
import org.eclipse.swt.widgets.Combo;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    45
import org.eclipse.swt.widgets.Composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    46
import org.eclipse.swt.widgets.Control;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    47
import org.eclipse.swt.widgets.Display;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    48
import org.eclipse.swt.widgets.Label;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    49
import org.eclipse.swt.widgets.Shell;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    50
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    51
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    52
import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    53
import com.nokia.carbide.remoteconnections.interfaces.IConnection;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    54
import com.nokia.carbide.remoteconnections.interfaces.IConnectionType;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    55
import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    56
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    57
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    58
import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    59
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    60
/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    61
 *	This dialog allows in-depth configuration of the connection settings.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    62
 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    63
@SuppressWarnings("restriction")
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    64
public class ConnectToDeviceDialog extends AbstractLaunchSettingsDialog implements IConnectionListener {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    65
	private IConnectionsManager manager;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    66
	private IConnectionTypeProvider typeProvider;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    67
	private ComboViewer viewer;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    68
	private Button editButton;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    69
	private Label descriptionLabel;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    70
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    71
	protected ConnectToDeviceDialog(Shell shell, LaunchWizardData data) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    72
		super(shell, data);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    73
		manager = RemoteConnectionsActivator.getConnectionsManager();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    74
		typeProvider = RemoteConnectionsActivator.getConnectionTypeProvider();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    75
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    76
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    77
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    78
	protected Control createDialogArea(Composite parent) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    79
		final Composite composite = initDialogArea(parent, 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    80
				"Change connection",
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    81
				LaunchWizardHelpIds.WIZARD_DIALOG_CHANGE_CONNECTION);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    82
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    83
		Composite viewerGroup = new Composite(composite, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    84
		GridDataFactory.fillDefaults().applyTo(viewerGroup);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    85
		GridLayoutFactory.swtDefaults().numColumns(3).applyTo(viewerGroup);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    86
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    87
		Label label = new Label(viewerGroup, SWT.NONE);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    88
		label.setText("Current connection");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    89
		GridDataFactory.defaultsFor(label).applyTo(label);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    90
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    91
		viewer = new ComboViewer(viewerGroup, SWT.READ_ONLY);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    92
		viewer.setLabelProvider(new LabelProvider() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    93
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    94
			public String getText(Object element) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    95
				if (element instanceof IConnection)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    96
					return ((IConnection) element).getDisplayName();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    97
				
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    98
				return "No Current connection";
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
    99
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   100
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   101
		viewer.setContentProvider(new ArrayContentProvider());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   102
		Combo combo = viewer.getCombo();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   103
		GridDataFactory.defaultsFor(combo).grab(true, false).applyTo(combo);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   104
		viewer.getControl().setData(UID, "combo_viewer"); //$NON-NLS-1$
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   105
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   106
			public void selectionChanged(SelectionChangedEvent event) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   107
				if (getDialogArea() != null)
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   108
					connectionSelected(getConnectionFromSelection(event.getSelection()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   109
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   110
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   111
		manager.addConnectionListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   112
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   113
		editButton = new Button(viewerGroup, SWT.PUSH);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   114
		editButton.setText("Edit...");
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   115
		GridDataFactory.defaultsFor(editButton).applyTo(editButton);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   116
		editButton.setData(UID, "edit_button"); //$NON-NLS-1$
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   117
		editButton.addSelectionListener(new SelectionAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   118
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   119
			public void widgetSelected(SelectionEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   120
				IConnection connection = getConnectionFromSelection(viewer.getSelection()); 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   121
				if (connection != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   122
					SettingsWizard wizard = new SettingsWizard(connection, data.getService());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   123
					wizard.open(composite.getShell());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   124
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   125
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   126
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   127
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   128
		descriptionLabel = new Label(composite, SWT.WRAP);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   129
		GridDataFactory.defaultsFor(descriptionLabel).grab(false, true).applyTo(descriptionLabel);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   130
		composite.addControlListener(new ControlAdapter() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   131
			@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   132
			public void controlResized(ControlEvent e) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   133
				descriptionLabel.pack();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   134
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   135
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   136
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   137
		setViewerInput(data.getConnection());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   138
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   139
		return composite;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   140
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   141
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   142
	protected void validate() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   143
		IStatus status = ConnectToDeviceSection.revalidate(data);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   144
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   145
		if (status.isOK()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   146
			IConnection connection = data.getConnection();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   147
			if (connection != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   148
				IConnectedService connectedService = null;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   149
				Collection<IConnectedService> services = manager.getConnectedServices(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   150
				if (services != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   151
					for (IConnectedService service : services) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   152
						if (service != null && service.getService().getIdentifier().equals(data.getService().getIdentifier())) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   153
							connectedService = service;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   154
						}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   155
					}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   156
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   157
				
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   158
				if (connectedService == null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   159
					status = error(MessageFormat.format(
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   160
							"The selected connection does not support {0}",
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   161
							data.getService().getDisplayName()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   162
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   163
				else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   164
					com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus serviceStatus = 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   165
						connectedService.getStatus();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   166
					if (!serviceStatus.getEStatus().equals(
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   167
							com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus.UP)) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   168
						status = warning("The selected connection may not be usable for debugging:\n {0}", 
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   169
								serviceStatus.getLongDescription());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   170
					}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   171
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   172
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   173
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   174
		updateStatus(status);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   175
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   176
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   177
	/**
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   178
	 *	Update for a change in the connection.  We will attempt to connect to the
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   179
	 *  device (once) to detect what TRK it is running.
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   180
	 */
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   181
	private void updateConnection(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   182
		String standardPNPMessage = ConnectToDeviceSection.getStandardPNPMessage();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   183
		data.setConnection(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   184
		if (connection != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   185
			descriptionLabel.setText(standardPNPMessage);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   186
		} else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   187
			descriptionLabel.setText("No connections are detected or defined.  " + standardPNPMessage);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   188
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   189
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   190
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   191
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   192
	public void connectionSelected(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   193
		updateConnection(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   194
		validate();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   195
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   196
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   197
	public void connectionAdded(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   198
		refreshUI();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   199
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   200
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   201
	public void connectionRemoved(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   202
		refreshUI();		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   203
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   204
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   205
	public void currentConnectionSet(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   206
		refreshUI();		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   207
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   208
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   209
	private Set<IConnectionType> getCompatibleConnectionTypes() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   210
		HashSet<IConnectionType> types = new HashSet<IConnectionType>();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   211
		Collection<String> compatibleTypeIds =
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   212
			typeProvider.getCompatibleConnectionTypeIds(data.getService());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   213
		for (String typeId : compatibleTypeIds) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   214
			types.add(typeProvider.getConnectionType(typeId));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   215
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   216
		return types;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   217
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   218
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   219
	private List<IConnection> getCompatibleConnections() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   220
		Set<IConnectionType> types = getCompatibleConnectionTypes();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   221
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   222
		List<IConnection> compatibleConnections = new ArrayList<IConnection>();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   223
		for (IConnection connection : manager.getConnections()) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   224
			if (types.contains(connection.getConnectionType()))
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   225
				compatibleConnections.add(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   226
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   227
		return compatibleConnections;
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   228
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   229
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   230
	private void setViewerInput(IConnection connection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   231
		List<IConnection> connections = getCompatibleConnections();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   232
		viewer.setInput(connections);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   233
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   234
		if (connections.isEmpty())
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   235
			viewer.getCombo().setEnabled(false);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   236
		else {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   237
			viewer.getCombo().setEnabled(true);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   238
			if (connection == null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   239
				viewer.getCombo().select(0);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   240
				ISelection selection = viewer.getSelection();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   241
				connection = getConnectionFromSelection(selection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   242
				viewer.setSelection(selection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   243
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   244
			else
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   245
				viewer.setSelection(new StructuredSelection(connection));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   246
		}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   247
		editButton.setEnabled(!viewer.getSelection().isEmpty());
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   248
		
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   249
		// fire listener in case we selected anew or the current connection changed
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   250
		connectionSelected(connection);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   251
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   252
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   253
	private IConnection getConnectionFromSelection(ISelection selection) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   254
		return (IConnection) ((IStructuredSelection) selection).getFirstElement();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   255
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   256
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   257
	private void refreshUI() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   258
		Display.getDefault().syncExec(new Runnable() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   259
			public void run() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   260
				if (viewer != null && viewer.getContentProvider() != null) {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   261
					setViewerInput(getConnectionFromSelection(viewer.getSelection()));
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   262
				}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   263
			}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   264
		});
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   265
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   266
	
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   267
	@Override
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   268
	public boolean close() {
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   269
		manager.addConnectionListener(this);
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   270
		return super.close();
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   271
	}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   272
}
d1e221a2875f new launch wizard implementation
dadubrow
parents:
diff changeset
   273