connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionTypePage.java
branchRCL_2_4
changeset 857 d66843399035
parent 337 c44c75698736
equal deleted inserted replaced
855:3f37e327885c 857:d66843399035
    19 package com.nokia.carbide.remoteconnections.settings.ui;
    19 package com.nokia.carbide.remoteconnections.settings.ui;
    20 
    20 
    21 import com.nokia.carbide.remoteconnections.Messages;
    21 import com.nokia.carbide.remoteconnections.Messages;
    22 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
    22 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
    23 import com.nokia.carbide.remoteconnections.interfaces.*;
    23 import com.nokia.carbide.remoteconnections.interfaces.*;
       
    24 import com.nokia.carbide.remoteconnections.internal.registry.Registry;
    24 import com.nokia.cpp.internal.api.utils.core.Check;
    25 import com.nokia.cpp.internal.api.utils.core.Check;
    25 
    26 
    26 import org.eclipse.jface.viewers.*;
    27 import org.eclipse.jface.viewers.*;
    27 import org.eclipse.jface.wizard.WizardPage;
    28 import org.eclipse.jface.wizard.WizardPage;
    28 import org.eclipse.swt.SWT;
    29 import org.eclipse.swt.SWT;
    72 		nameText.addModifyListener(new ModifyListener() {
    73 		nameText.addModifyListener(new ModifyListener() {
    73 			public void modifyText(ModifyEvent e) {
    74 			public void modifyText(ModifyEvent e) {
    74 				setPageComplete(validatePage());
    75 				setPageComplete(validatePage());
    75 			}
    76 			}
    76 		});
    77 		});
       
    78 		boolean canEditConnection = !settingsWizard.isConnectionToEditDynamic();
       
    79 		nameText.setEnabled(canEditConnection);
    77 
    80 
    78 		Label label = new Label(container, SWT.NONE);
    81 		Label label = new Label(container, SWT.NONE);
    79 		label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    82 		label.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, false));
    80 		label.setText(Messages.getString("ConnectionTypePage.ViewerLabel")); //$NON-NLS-1$
    83 		label.setText(Messages.getString("ConnectionTypePage.ViewerLabel")); //$NON-NLS-1$
    81 		
    84 		
   117 				IConnectionType t2 = (IConnectionType) e2;
   120 				IConnectionType t2 = (IConnectionType) e2;
   118 				return t1.getDisplayName().compareToIgnoreCase(t2.getDisplayName());
   121 				return t1.getDisplayName().compareToIgnoreCase(t2.getDisplayName());
   119 			}
   122 			}
   120 		});
   123 		});
   121 		viewer.getList().select(getCurrentTypeIndex());
   124 		viewer.getList().select(getCurrentTypeIndex());
       
   125 		viewer.getList().setEnabled(canEditConnection);
   122 		
   126 		
   123 		connectionTypeDescLabel = new Label(container, SWT.WRAP);
   127 		connectionTypeDescLabel = new Label(container, SWT.WRAP);
   124 		connectionTypeDescLabel.setText(getConnectionTypeDescription());
   128 		connectionTypeDescLabel.setText(getConnectionTypeDescription());
   125 		gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
   129 		gd = new GridData(SWT.FILL, SWT.CENTER, true, false);
   126 		gd.horizontalSpan = 2;
   130 		gd.horizontalSpan = 2;
   139 	}
   143 	}
   140 	
   144 	
   141 	private String getServicesString() {
   145 	private String getServicesString() {
   142 		StringBuilder servicesString = new StringBuilder();
   146 		StringBuilder servicesString = new StringBuilder();
   143 		Collection<IService> services = 
   147 		Collection<IService> services = 
   144 			RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleServices(getConnectionType());
   148 			Registry.instance().getCompatibleServices(getConnectionType());
   145 		if (services == null || services.isEmpty())
   149 		if (services == null || services.isEmpty())
   146 			return ""; //$NON-NLS-1$
   150 			return ""; //$NON-NLS-1$
   147 		for (Iterator<IService> iterator = services.iterator(); iterator.hasNext();) {
   151 		for (Iterator<IService> iterator = services.iterator(); iterator.hasNext();) {
   148 			servicesString.append(iterator.next().getDisplayName());
   152 			servicesString.append(iterator.next().getDisplayName());
   149 			if (iterator.hasNext())
   153 			if (iterator.hasNext())
   155 
   159 
   156 	private String getConnectionTypeDescription() {
   160 	private String getConnectionTypeDescription() {
   157 		return getConnectionType().getDescription();
   161 		return getConnectionType().getDescription();
   158 	}
   162 	}
   159 	
   163 	
       
   164 	@SuppressWarnings("unchecked")
   160 	private int getCurrentTypeIndex() {
   165 	private int getCurrentTypeIndex() {
   161 		IConnection connectionToEdit = settingsWizard.getConnectionToEdit();
   166 		IConnection connectionToEdit = settingsWizard.getConnectionToEdit();
   162 		if (connectionToEdit != null) {
   167 		if (connectionToEdit != null) {
   163 			Object input = viewer.getInput();
   168 			Object input = viewer.getInput();
   164 			if (input != null) {
   169 			if (input != null) {
   165 				Collection<IConnectionType> connectionTypes = (Collection<IConnectionType>) input;
   170 				Collection<IConnectionType> connectionTypes = (Collection) input;
   166 				for (int i = 0; i < connectionTypes.size(); i++) {
   171 				for (int i = 0; i < connectionTypes.size(); i++) {
   167 					IConnectionType connectionType = (IConnectionType) viewer.getElementAt(i);
   172 					IConnectionType connectionType = (IConnectionType) viewer.getElementAt(i);
   168 					if (connectionToEdit.getConnectionType().equals(connectionType))
   173 					if (connectionToEdit.getConnectionType().equals(connectionType))
   169 						return i;
   174 						return i;
   170 				}
   175 				}
   177 		Collection<IConnectionType> connectionTypes = getValidConnectionTypes();
   182 		Collection<IConnectionType> connectionTypes = getValidConnectionTypes();
   178 		IService serviceToRestrict = settingsWizard.getServiceToRestrict();
   183 		IService serviceToRestrict = settingsWizard.getServiceToRestrict();
   179 		if (serviceToRestrict != null) {
   184 		if (serviceToRestrict != null) {
   180 			List<IConnectionType> restrictedConnectionTypes = new ArrayList<IConnectionType>();
   185 			List<IConnectionType> restrictedConnectionTypes = new ArrayList<IConnectionType>();
   181 			Collection<String> compatibleConnectionTypeIds = 
   186 			Collection<String> compatibleConnectionTypeIds = 
   182 				RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleConnectionTypeIds(serviceToRestrict);
   187 				Registry.instance().getCompatibleConnectionTypeIds(serviceToRestrict);
   183 			for (String connectionTypeId : compatibleConnectionTypeIds) {
   188 			for (String connectionTypeId : compatibleConnectionTypeIds) {
   184 				IConnectionType connectionType = 
   189 				IConnectionType connectionType = 
   185 					RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionType(connectionTypeId);
   190 					Registry.instance().getConnectionType(connectionTypeId);
   186 				if (connectionTypes.contains(connectionType))
   191 				if (connectionTypes.contains(connectionType))
   187 					restrictedConnectionTypes.add(connectionType);
   192 					restrictedConnectionTypes.add(connectionType);
   188 			}
   193 			}
   189 			return restrictedConnectionTypes;
   194 			return restrictedConnectionTypes;
   190 		}
   195 		}
   195 	private Collection<IConnectionType> getValidConnectionTypes() {
   200 	private Collection<IConnectionType> getValidConnectionTypes() {
   196 		// valid connection types have at least one compatible service, or are the actual connection type of the connection being edited
   201 		// valid connection types have at least one compatible service, or are the actual connection type of the connection being edited
   197 		IConnection connectionToEdit = settingsWizard.getConnectionToEdit();
   202 		IConnection connectionToEdit = settingsWizard.getConnectionToEdit();
   198 		IConnectionType connectionTypeToEdit = connectionToEdit != null ? connectionToEdit.getConnectionType() : null;
   203 		IConnectionType connectionTypeToEdit = connectionToEdit != null ? connectionToEdit.getConnectionType() : null;
   199 		Collection<IConnectionType> allConnectionTypes = 
   204 		Collection<IConnectionType> allConnectionTypes = 
   200 		RemoteConnectionsActivator.getConnectionTypeProvider().getConnectionTypes();
   205 		Registry.instance().getConnectionTypes();
   201 		Collection<IConnectionType> connectionTypes = new ArrayList<IConnectionType>();
   206 		Collection<IConnectionType> connectionTypes = new ArrayList<IConnectionType>();
   202 		for (IConnectionType connectionType : allConnectionTypes) {
   207 		for (IConnectionType connectionType : allConnectionTypes) {
   203 			if (!RemoteConnectionsActivator.getConnectionTypeProvider().getCompatibleServices(connectionType).isEmpty() ||
   208 			if (!Registry.instance().getCompatibleServices(connectionType).isEmpty() ||
   204 					connectionType.equals(connectionTypeToEdit))
   209 					connectionType.equals(connectionTypeToEdit))
   205 				connectionTypes.add(connectionType);
   210 				connectionTypes.add(connectionType);
   206 		}
   211 		}
   207 		return connectionTypes;
   212 		return connectionTypes;
   208 	}
   213 	}
   217 		
   222 		
   218 		return isValid;
   223 		return isValid;
   219 	}
   224 	}
   220 	
   225 	
   221 	private boolean isNameUnique(String name) {
   226 	private boolean isNameUnique(String name) {
   222 		boolean inUse = RemoteConnectionsActivator.getConnectionsManager().connectionNameInUse(name);
   227 		boolean inUse = Registry.instance().connectionNameInUse(name);
   223 		IConnection connectionToEdit = settingsWizard.getConnectionToEdit();
   228 		IConnection connectionToEdit = settingsWizard.getConnectionToEdit();
   224 		if (connectionToEdit != null && inUse)
   229 		if (connectionToEdit != null && inUse)
   225 			inUse = !name.equals(connectionToEdit.getDisplayName());
   230 			inUse = !name.equals(connectionToEdit.getDisplayName());
   226 		
   231 		
   227 		return !inUse;
   232 		return !inUse;