connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/ClientServiceSiteUI2.java
author Ed Swartz <ed.swartz@nokia.com>
Fri, 23 Apr 2010 14:15:21 -0500
changeset 1275 9e9250d7a09b
parent 1274 d2ec5b43969e
child 1557 c431b953b863
permissions -rw-r--r--
Fix connection selector defaults
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     1
/*
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     2
* Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     3
* All rights reserved.
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     4
* This component and the accompanying materials are made available
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     5
* under the terms of the License "Eclipse Public License v1.0"
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     6
* which accompanies this distribution, and is available
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     8
*
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
     9
* Initial Contributors:
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    11
*
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    12
* Contributors:
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    13
*
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    14
* Description: 
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    15
*
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    16
*/
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    17
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    18
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    19
package com.nokia.carbide.remoteconnections.internal.ui;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    20
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    21
import com.nokia.carbide.remoteconnections.Messages;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    22
import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    23
import com.nokia.carbide.remoteconnections.interfaces.*;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    24
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    25
import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    26
import com.nokia.carbide.remoteconnections.internal.registry.Registry;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    27
import com.nokia.carbide.remoteconnections.settings.ui.SettingsWizard;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    28
import com.nokia.cpp.internal.api.utils.core.Check;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    29
import com.nokia.cpp.internal.api.utils.core.ListenerList;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    30
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
    31
import org.eclipse.core.runtime.IStatus;
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
    32
import org.eclipse.core.runtime.Status;
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    33
import org.eclipse.jface.dialogs.Dialog;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    34
import org.eclipse.jface.dialogs.IDialogConstants;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    35
import org.eclipse.jface.resource.JFaceResources;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    36
import org.eclipse.jface.viewers.*;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    37
import org.eclipse.swt.SWT;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    38
import org.eclipse.swt.events.DisposeEvent;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    39
import org.eclipse.swt.events.DisposeListener;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    40
import org.eclipse.swt.events.SelectionAdapter;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    41
import org.eclipse.swt.events.SelectionEvent;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    42
import org.eclipse.swt.graphics.*;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    43
import org.eclipse.swt.layout.GridData;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    44
import org.eclipse.swt.layout.GridLayout;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    45
import org.eclipse.swt.widgets.*;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    46
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    47
import java.text.MessageFormat;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    48
import java.util.*;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    49
import java.util.List;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    50
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    51
/**
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    52
 * Implementation of IClientServiceSiteUI2
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    53
 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    54
@SuppressWarnings("deprecation")
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    55
public class ClientServiceSiteUI2 implements IClientServiceSiteUI2, IConnectionListener, IConnectionsManagerListener {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    56
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    57
	private IService service;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    58
	private ComboViewer viewer;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    59
	private FontMetrics fm;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    60
	private Set<IConnectionType> compatibleConnectionTypes;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    61
	private Button editButton;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    62
	private Button newButton;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    63
	private String connection;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    64
	private ListenerList<IListener> listenerList;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    65
	private static final String UID = ".uid"; //$NON-NLS-1$
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    66
	private Map<String, String> connectionNames;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    67
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    68
	public ClientServiceSiteUI2(IService service) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    69
		Check.checkArg(service);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    70
		this.service = service;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    71
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    72
	
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    73
	public void createComposite(Composite parent) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    74
		initializeDialogUnits(parent);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    75
		Group group = new Group(parent, SWT.NONE);
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
    76
		group.setText(Messages.getString("ClientServiceSiteUI2.UseConnectionGroupLabel")); //$NON-NLS-1$
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    77
		group.setLayout(new GridLayout());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    78
		group.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    79
		group.setData(UID, "useConnectionGroup"); //$NON-NLS-1$
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    80
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    81
		viewer = new ComboViewer(group, SWT.READ_ONLY);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    82
		viewer.setLabelProvider(new LabelProvider() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    83
			@Override
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    84
			public String getText(Object element) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    85
				Check.checkContract(element instanceof String);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    86
				String id = (String) element;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    87
				return connectionNames.get(id);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    88
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    89
		});
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    90
		viewer.setContentProvider(new ArrayContentProvider());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    91
		GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    92
		viewer.getCombo().setLayoutData(gd);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    93
		viewer.getControl().setData(UID, "viewer"); //$NON-NLS-1$
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    94
		viewer.addSelectionChangedListener(new ISelectionChangedListener() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    95
			public void selectionChanged(SelectionChangedEvent event) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    96
				IStructuredSelection selection = (IStructuredSelection) event.getSelection();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    97
				String connection = (String) selection.getFirstElement();
1274
d2ec5b43969e Fix NPE
Ed Swartz <ed.swartz@nokia.com>
parents: 1265
diff changeset
    98
				if (connection != null && !connection.equals(ClientServiceSiteUI2.this.connection)) {
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
    99
					ClientServiceSiteUI2.this.connection = connection;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   100
					fireConnectionSelected();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   101
				}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   102
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   103
		});
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   104
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   105
		final Composite composite = new Composite(group, SWT.NONE);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   106
		GridLayout layout = new GridLayout();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   107
		layout.numColumns = 2;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   108
		layout.makeColumnsEqualWidth = true;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   109
		layout.marginWidth = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_MARGIN);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   110
		layout.marginHeight = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_MARGIN);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   111
		layout.horizontalSpacing = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.HORIZONTAL_SPACING);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   112
		layout.verticalSpacing = Dialog.convertVerticalDLUsToPixels(fm, IDialogConstants.VERTICAL_SPACING);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   113
		composite.setLayout(layout);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   114
		gd = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_CENTER);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   115
		composite.setLayoutData(gd);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   116
		composite.setFont(parent.getFont());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   117
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   118
		newButton = new Button(composite, SWT.PUSH);
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   119
		newButton.setText(Messages.getString("ClientServiceSiteUI2.NewButtonLabel")); //$NON-NLS-1$
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   120
		newButton.setFont(JFaceResources.getDialogFont());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   121
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   122
		int widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   123
		Point minSize = newButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   124
		gd.widthHint = Math.max(widthHint, minSize.x);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   125
		newButton.setLayoutData(gd);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   126
		newButton.setData(UID, "newButton"); //$NON-NLS-1$
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   127
		newButton.addSelectionListener(new SelectionAdapter() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   128
			@Override
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   129
			public void widgetSelected(SelectionEvent e) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   130
				SettingsWizard wizard = new SettingsWizard(null, service);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   131
				wizard.open(composite.getShell());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   132
				IConnection connection = wizard.getConnectionToEdit();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   133
				// note: refresh ASAP so the selection will be valid; but endure a listener event
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   134
				// which will redo this
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   135
				refreshUI();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   136
				setViewerInput(connection);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   137
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   138
		});
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   139
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   140
		editButton = new Button(composite, SWT.PUSH);
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   141
		editButton.setText(Messages.getString("ClientServiceSiteUI2.EditButtonLabel")); //$NON-NLS-1$
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   142
		editButton.setFont(JFaceResources.getDialogFont());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   143
		gd = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   144
		widthHint = Dialog.convertHorizontalDLUsToPixels(fm, IDialogConstants.BUTTON_WIDTH);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   145
		minSize = editButton.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   146
		gd.widthHint = Math.max(widthHint, minSize.x);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   147
		editButton.setLayoutData(gd);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   148
		editButton.setData(UID, "editButton"); //$NON-NLS-1$
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   149
		editButton.addSelectionListener(new SelectionAdapter() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   150
			@Override
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   151
			public void widgetSelected(SelectionEvent e) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   152
				IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   153
				Object value = selection.getFirstElement();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   154
				if (value instanceof String) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   155
					IConnection editConnection = getActualConnection((String) value);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   156
					SettingsWizard wizard = new SettingsWizard(editConnection, service);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   157
					wizard.open(composite.getShell());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   158
					
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   159
					// leave the viewer the same, callback will refresh anything needed
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   160
				}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   161
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   162
		});
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   163
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   164
		// attach listeners
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   165
		RemoteConnectionsActivator.getConnectionsManager().addConnectionListener(this);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   166
		RemoteConnectionsActivator.getConnectionsManager().addConnectionStoreChangedListener(this);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   167
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   168
		// remove listeners on dispose
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   169
		group.addDisposeListener(new DisposeListener() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   170
			
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   171
			public void widgetDisposed(DisposeEvent e) {
910
b142ab8c7bbd Fix bug - remove listeners on dispose
dadubrow
parents: 761
diff changeset
   172
				RemoteConnectionsActivator.getConnectionsManager().removeConnectionListener(ClientServiceSiteUI2.this);
b142ab8c7bbd Fix bug - remove listeners on dispose
dadubrow
parents: 761
diff changeset
   173
				RemoteConnectionsActivator.getConnectionsManager().removeConnectionStoreChangedListener(ClientServiceSiteUI2.this);
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   174
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   175
		});
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   176
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   177
		setViewerInput(null);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   178
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   179
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   180
	/**
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   181
	 * Get the actual connection for an identifier.
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   182
	 * This is not {@link IConnectionsManager#ensureConnection(String, IService)} because we don't
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   183
	 * want to actually validate the connection now.
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   184
	 * @param id
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   185
	 * @return {@link IConnection} or <code>null</code>
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   186
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   187
	protected IConnection getActualConnection(String id) {
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   188
		if (id == null) {
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   189
			return null;
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   190
		}
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   191
		if (id.equals(Registry.CURRENT_CONNECTION_ID)) {
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   192
			return RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection();
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   193
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   194
		for (IConnection connection : RemoteConnectionsActivator.getConnectionsManager().getConnections()) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   195
			if (connection.getIdentifier().equals(id)) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   196
				return connection;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   197
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   198
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   199
		return null;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   200
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   201
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   202
	/**
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   203
	 * Set the selected input.  
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   204
	 * @param connection existing connection or <code>null</code> for the current   
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   205
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   206
	private void setViewerInput(IConnection connection) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   207
		List<IConnection> compatible = getCompatibleConnections();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   208
		connectionNames = new LinkedHashMap<String, String>();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   209
		
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   210
		// update the current
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   211
		IConnection currentConnection = RemoteConnectionsActivator.getConnectionsManager().getCurrentConnection();
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   212
		
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   213
		connectionNames.put(Registry.CURRENT_CONNECTION_ID, createCurrentConnectionName(currentConnection));
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   214
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   215
		for (IConnection conn : compatible) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   216
			connectionNames.put(conn.getIdentifier(), conn.getDisplayName());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   217
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   218
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   219
		viewer.setInput(connectionNames.keySet());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   220
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   221
		if (connectionNames.isEmpty())
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   222
			viewer.getCombo().setEnabled(false);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   223
		else {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   224
			viewer.getCombo().setEnabled(true);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   225
			if (connection == null) {
1265
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   226
				String lastConnectionId = Registry.instance().getLastConnectionId();
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   227
				if (lastConnectionId != null) {
1275
9e9250d7a09b Fix connection selector defaults
Ed Swartz <ed.swartz@nokia.com>
parents: 1274
diff changeset
   228
					viewer.getCombo().select(0);  // the default setting
9e9250d7a09b Fix connection selector defaults
Ed Swartz <ed.swartz@nokia.com>
parents: 1274
diff changeset
   229
					selectConnection(lastConnectionId);  // should override if connection still exists
1265
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   230
				} else {
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   231
					viewer.getCombo().select(0);
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   232
					viewer.setSelection(viewer.getSelection());
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   233
				}
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   234
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   235
			else
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   236
				selectConnection(connection.getIdentifier());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   237
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   238
		editButton.setEnabled(!viewer.getSelection().isEmpty());
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   239
		
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   240
		// fire listener in case we selected anew or the current connection changed
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   241
		fireConnectionSelected();
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   242
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   243
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   244
	private void refreshUI() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   245
		Display.getDefault().syncExec(new Runnable() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   246
			public void run() {
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   247
				if (viewer != null && viewer.getContentProvider() != null) {
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   248
					
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   249
					// try to preserve the currently selected item, if it's a concrete
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   250
					// connection; if it's current, allow for the new current to be chosen.
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   251
					IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   252
					Object value = selection.getFirstElement();
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   253
					String current = null;
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   254
					if (value instanceof String) {
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   255
						current = (String) value;
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   256
					}
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   257
					if (Registry.CURRENT_CONNECTION_ID.equals(current)) {
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   258
						current = null;
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   259
					}
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   260
					setViewerInput(getActualConnection(current));
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   261
				}
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   262
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   263
		});
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   264
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   265
	
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   266
	/**
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   267
	 * @param currentConnection
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   268
	 * @return
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   269
	 */
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   270
	private String createCurrentConnectionName(IConnection currentConnection) {
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   271
		return MessageFormat.format(Messages.getString("ClientServiceSiteUI2.CurrentConnectionFormat"), //$NON-NLS-1$
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   272
				currentConnection != null ? currentConnection.getDisplayName() : 
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   273
					Messages.getString("ClientServiceSiteUI2.CurrentConnection_NoneDetected")); //$NON-NLS-1$
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   274
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   275
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   276
	private void initializeDialogUnits(Composite parent) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   277
		GC gc = new GC(parent);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   278
		gc.setFont(JFaceResources.getDialogFont());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   279
		fm = gc.getFontMetrics();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   280
		gc.dispose();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   281
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   282
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   283
	private List<IConnection> getCompatibleConnections() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   284
		getCompatibleConnectionTypes();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   285
		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   286
		List<IConnection> compatibleConnections = new ArrayList<IConnection>();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   287
		for (IConnection connection : Registry.instance().getConnections()) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   288
			if (isCompatibleConnection(connection))
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   289
				compatibleConnections.add(connection);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   290
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   291
		return compatibleConnections;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   292
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   293
	
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   294
	private boolean isCompatibleConnection(IConnection connection) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   295
		return compatibleConnectionTypes.contains(connection.getConnectionType());
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   296
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   297
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   298
	private void getCompatibleConnectionTypes() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   299
		compatibleConnectionTypes = new HashSet<IConnectionType>();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   300
		Collection<String> compatibleTypeIds =
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   301
			Registry.instance().getCompatibleConnectionTypeIds(service);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   302
		for (String typeId : compatibleTypeIds) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   303
			compatibleConnectionTypes.add(
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   304
					Registry.instance().getConnectionType(typeId));
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   305
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   306
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   307
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   308
	public void selectConnection(String connection) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   309
		viewer.setSelection(new StructuredSelection(connection));
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   310
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   311
	
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   312
	public String getSelectedConnection() {
1265
f90f47d3882f PlatSim-related launch wizard changes: (1) Remember last connection created and offer this by default in the Select Connection dialog; (2) Immediately open New Connection dialog if debugging and no connections exist; (3) Split out SelectConnectionDialog; (4) Fix some wording in Select Connection dialog since this is not always an error situation.
Ed Swartz <ed.swartz@nokia.com>
parents: 910
diff changeset
   313
		Registry.instance().setLastConnectionId(connection);
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   314
		return connection;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   315
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   316
	
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   317
	public IStatus getSelectionStatus() {
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   318
		String requiredConnectionTypes = getAllowedConnectionTypesString();
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   319
		
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   320
		// no selection yet...?
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   321
		if (connection == null) {
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   322
			return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID,
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   323
					MessageFormat.format(
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   324
							Messages.getString("ClientServiceSiteUI2.NoConnectionError"), //$NON-NLS-1$
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   325
							service.getDisplayName(),
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   326
							requiredConnectionTypes));
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   327
		}
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   328
		
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   329
		// check whether the current is compatible with the service and connection type
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   330
		if (Registry.CURRENT_CONNECTION_ID.equals(connection)) {
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   331
			IConnection actual = getActualConnection(connection);
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   332
			if (actual == null) {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   333
				return new Status(IStatus.ERROR, RemoteConnectionsActivator.PLUGIN_ID,
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   334
						MessageFormat.format(
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   335
							Messages.getString("ClientServiceSiteUI2.NoCurrentConnection"), //$NON-NLS-1$
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   336
							service.getDisplayName(),
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   337
							requiredConnectionTypes));
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   338
			}
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   339
			
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   340
			// is the service supported?
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   341
			boolean found = false;
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   342
			for (IConnectedService aService : Registry.instance().getConnectedServices(actual)) {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   343
				if (service.getIdentifier().equals(aService.getService().getIdentifier())) {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   344
					found = true;
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   345
					break;
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   346
				}
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   347
			}
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   348
			if (!found) {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   349
				return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID,
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   350
						MessageFormat.format(
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   351
								Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionService") //$NON-NLS-1$
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   352
								+ "\n"  //$NON-NLS-1$
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   353
								+ Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   354
								actual.getDisplayName(),
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   355
								service.getDisplayName()));
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   356
			}
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   357
			
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   358
			// is the hardware type supported by the service?
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   359
			if (!isCompatibleConnection(actual)) {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   360
				return new Status(IStatus.WARNING, RemoteConnectionsActivator.PLUGIN_ID,
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   361
						MessageFormat.format(
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   362
								Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionType") //$NON-NLS-1$
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   363
								+ "\n"  //$NON-NLS-1$
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   364
								+ Messages.getString("ClientServiceSiteUI2.IncompatibleCurrentConnectionFixupAdvice"), //$NON-NLS-1$
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   365
								actual.getDisplayName(),
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   366
								requiredConnectionTypes));
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   367
		
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   368
			}
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   369
		}
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   370
		
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   371
		// otherwise, it's okay!
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   372
		return Status.OK_STATUS;
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   373
	}
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   374
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   375
	private String getAllowedConnectionTypesString() {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   376
		StringBuilder requiredConnectionTypes = new StringBuilder();
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   377
		IConnectionType[] connectionTypes = 
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   378
			(IConnectionType[]) compatibleConnectionTypes.toArray(new IConnectionType[compatibleConnectionTypes.size()]);
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   379
		for (int i = 0; i < connectionTypes.length; i++) {
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   380
			IConnectionType type = connectionTypes[i];
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   381
			if (requiredConnectionTypes.length() > 0)
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   382
				requiredConnectionTypes.append(", "); //$NON-NLS-1$
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   383
			if (i == connectionTypes.length - 1)
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   384
				requiredConnectionTypes.append(Messages.getString("ClientServiceSiteUI2.Or")); //$NON-NLS-1$
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   385
			requiredConnectionTypes.append(type.getDisplayName());
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   386
		}
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   387
		return requiredConnectionTypes.toString();
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   388
	}
730
8ecd45ef360e Fix up some issues found when using the random connected service provider. Also, move validation checks of IClientServiceSiteUI2 into a method of that interface, since we need to handle the case where the default connection is currently incompatible.
Ed Swartz <ed.swartz@nokia.com>
parents: 728
diff changeset
   389
	
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   390
	/* (non-Javadoc)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   391
	 * @see com.nokia.carbide.remoteconnections.interfaces.IClientServiceSiteUI2#getConnectionDisplayName(java.lang.String)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   392
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   393
	public String getConnectionDisplayName(String connection) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   394
		String display = connectionNames.get(connection);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   395
		if (display == null)
731
68bc07acac96 Improve error checking and messages when default connection is inappropriate or no connections exist.
Ed Swartz <ed.swartz@nokia.com>
parents: 730
diff changeset
   396
			display = MessageFormat.format(Messages.getString("ClientServiceSiteUI2.DeletedConnectionDisplayName"), connection); //$NON-NLS-1$
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   397
		return display;
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   398
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   399
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   400
	public void addListener(IListener listener) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   401
		if (listenerList == null)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   402
			listenerList = new ListenerList<IListener>();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   403
		listenerList.add(listener);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   404
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   405
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   406
	public void removeListener(IListener listener) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   407
		if (listenerList != null)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   408
			listenerList.remove(listener);
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   409
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   410
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   411
	private void fireConnectionSelected() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   412
		if (listenerList != null) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   413
			for (IListener listener : listenerList) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   414
				listener.connectionSelected();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   415
			}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   416
		}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   417
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   418
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   419
	/* (non-Javadoc)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   420
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionAdded(com.nokia.carbide.remoteconnections.interfaces.IConnection)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   421
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   422
	public void connectionAdded(IConnection connection) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   423
		refreshUI();
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   424
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   425
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   426
	/* (non-Javadoc)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   427
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#connectionRemoved(com.nokia.carbide.remoteconnections.interfaces.IConnection)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   428
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   429
	public void connectionRemoved(IConnection connection) {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   430
		refreshUI();		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   431
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   432
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   433
	/* (non-Javadoc)
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   434
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionListener#currentConnectionSet(com.nokia.carbide.remoteconnections.interfaces.IConnection)
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   435
	 */
761
19123c07e2ab Refactor API and related from default connection to current + update heuristics
dadubrow
parents: 731
diff changeset
   436
	public void currentConnectionSet(IConnection connection) {
728
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   437
		refreshUI();		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   438
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   439
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   440
	/* (non-Javadoc)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   441
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#connectionStoreChanged()
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   442
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   443
	public void connectionStoreChanged() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   444
		refreshUI();		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   445
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   446
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   447
	/* (non-Javadoc)
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   448
	 * @see com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager.IConnectionsManagerListener#displayChanged()
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   449
	 */
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   450
	public void displayChanged() {
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   451
		refreshUI();		
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   452
	}
a39d0ba41f81 Initial work for bug #10418
Ed Swartz <ed.swartz@nokia.com>
parents:
diff changeset
   453
}