81 import org.eclipse.swt.widgets.Text; |
81 import org.eclipse.swt.widgets.Text; |
82 import org.eclipse.ui.ISharedImages; |
82 import org.eclipse.ui.ISharedImages; |
83 import org.eclipse.ui.PlatformUI; |
83 import org.eclipse.ui.PlatformUI; |
84 import org.osgi.framework.Version; |
84 import org.osgi.framework.Version; |
85 |
85 |
86 import com.nokia.carbide.installpackages.InstallPackages; |
|
87 import com.nokia.carbide.remoteconnections.Messages; |
86 import com.nokia.carbide.remoteconnections.Messages; |
88 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
87 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator; |
89 import com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService2; |
88 import com.nokia.carbide.remoteconnections.interfaces.AbstractConnectedService2; |
90 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
89 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService; |
|
90 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
|
91 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
92 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
91 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
93 import com.nokia.carbide.remoteconnections.interfaces.IConnection; |
92 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory; |
94 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory; |
|
95 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory.IValidationErrorReporter; |
93 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory2; |
96 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory2; |
|
97 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory2.ISettingsChangedListener; |
94 import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; |
98 import com.nokia.carbide.remoteconnections.interfaces.IConnectionType; |
95 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
99 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
96 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider; |
100 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider; |
|
101 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller; |
|
102 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller.IPackageContents; |
97 import com.nokia.carbide.remoteconnections.interfaces.IService; |
103 import com.nokia.carbide.remoteconnections.interfaces.IService; |
98 import com.nokia.carbide.remoteconnections.interfaces.IService2; |
104 import com.nokia.carbide.remoteconnections.interfaces.IService2; |
99 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus; |
105 import com.nokia.carbide.remoteconnections.internal.api.IConnectedService2; |
100 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener; |
|
101 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus; |
|
102 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory.IValidationErrorReporter; |
|
103 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory2.ISettingsChangedListener; |
|
104 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller; |
|
105 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller.IPackageContents; |
|
106 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
106 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
107 import com.nokia.cpp.internal.api.utils.core.Check; |
107 import com.nokia.cpp.internal.api.utils.core.Check; |
108 import com.nokia.cpp.internal.api.utils.core.FileUtils; |
108 import com.nokia.cpp.internal.api.utils.core.FileUtils; |
109 import com.nokia.cpp.internal.api.utils.core.HostOS; |
109 import com.nokia.cpp.internal.api.utils.core.HostOS; |
|
110 import com.nokia.cpp.internal.api.utils.core.ObjectUtils; |
110 import com.nokia.cpp.internal.api.utils.core.Pair; |
111 import com.nokia.cpp.internal.api.utils.core.Pair; |
111 import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils; |
112 import com.nokia.cpp.internal.api.utils.ui.BrowseDialogUtils; |
112 |
113 |
113 public class ConnectionSettingsPage extends WizardPage implements ISettingsChangedListener { |
114 public class ConnectionSettingsPage extends WizardPage implements ISettingsChangedListener { |
114 |
115 |
305 deviceOSComboViewer.getCombo().setLayoutData(gd_sdkcombo); |
306 deviceOSComboViewer.getCombo().setLayoutData(gd_sdkcombo); |
306 deviceOSComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
307 deviceOSComboViewer.addSelectionChangedListener(new ISelectionChangedListener() { |
307 @SuppressWarnings("unchecked") |
308 @SuppressWarnings("unchecked") |
308 public void selectionChanged(SelectionChangedEvent event) { |
309 public void selectionChanged(SelectionChangedEvent event) { |
309 IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection(); |
310 IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection(); |
310 Pair<String, Version> pair = (Pair<String, Version>) selection.getFirstElement(); |
311 Pair<String, String> pair = (Pair<String, String>) selection.getFirstElement(); |
311 setSelectionToInstallComposite(pair); |
312 setSelectionToInstallComposite(pair); |
312 if (connectedService != null) |
313 if (connectedService instanceof IConnectedService2) |
313 connectedService.setDeviceOS(pair.first, pair.second); |
314 ((IConnectedService2) connectedService).setDeviceOS(pair.first, pair.second); |
314 } |
315 } |
315 }); |
316 }); |
316 deviceOSComboViewer.setContentProvider(new ArrayContentProvider()); |
317 deviceOSComboViewer.setContentProvider(new ArrayContentProvider()); |
317 deviceOSComboViewer.setLabelProvider(new LabelProvider() { |
318 deviceOSComboViewer.setLabelProvider(new LabelProvider() { |
318 @SuppressWarnings("unchecked") |
319 @SuppressWarnings({ "unchecked", "rawtypes" }) |
319 @Override |
320 @Override |
320 public String getText(Object element) { |
321 public String getText(Object element) { |
321 Check.checkState(element instanceof Pair); |
322 Check.checkState(element instanceof Pair); |
322 Pair<String, Version> pair = (Pair) element; |
323 Pair<String, Version> pair = (Pair) element; |
323 return MessageFormat.format("{0} {1}", pair.first, InstallPackages.formatSDKVersion(pair.second)); //$NON-NLS-1$ |
324 return MessageFormat.format("{0} {1}", pair.first, pair.second); //$NON-NLS-1$ |
324 } |
325 } |
325 }); |
326 }); |
326 deviceOSComboViewer.getControl().setToolTipText(Messages.getString("ConnectionSettingsPage.DeviceOSComboToolTip")); //$NON-NLS-1$ |
327 deviceOSComboViewer.getControl().setToolTipText(Messages.getString("ConnectionSettingsPage.DeviceOSComboToolTip")); //$NON-NLS-1$ |
327 deviceOSComboViewer.getControl().setData(UID, "deviceOSComboViewer"); //$NON-NLS-1$ |
328 deviceOSComboViewer.getControl().setData(UID, "deviceOSComboViewer"); //$NON-NLS-1$ |
328 } |
329 } |
735 } |
733 } |
736 }); |
734 }); |
737 |
735 |
738 } |
736 } |
739 |
737 |
740 protected void setSelectionToInstallComposite(Pair<String, Version> pair) { |
738 protected void setSelectionToInstallComposite(Pair<String, String> pair) { |
741 Object input = installerTreeViewer.getInput(); |
739 Object input = installerTreeViewer.getInput(); |
742 if (input instanceof TreeNode[]) { |
740 if (input instanceof TreeNode[]) { |
743 TreeNode node = findTreeNodeForPair((TreeNode[]) input, pair); |
741 TreeNode node = findTreeNodeForPair((TreeNode[]) input, pair); |
744 if (node != null) { |
742 if (node != null) { |
745 installerTreeViewer.collapseAll(); |
743 installerTreeViewer.collapseAll(); |
746 installerTreeViewer.setSelection(new StructuredSelection(node)); |
744 installerTreeViewer.setSelection(new StructuredSelection(node)); |
747 } |
745 } |
748 } |
746 } |
749 } |
747 } |
750 |
748 |
751 @SuppressWarnings("unchecked") |
749 private TreeNode findTreeNodeForPair(TreeNode[] treeNodes, Pair<String, String> pair) { |
752 private TreeNode findTreeNodeForPair(TreeNode[] treeNodes, Pair<String, Version> pair) { |
|
753 for (TreeNode treeNode : treeNodes) { |
750 for (TreeNode treeNode : treeNodes) { |
754 Object value = treeNode.getValue(); |
751 Object value = treeNode.getValue(); |
755 if (value instanceof IRemoteAgentInstaller) { |
752 if (value instanceof IRemoteAgentInstaller) { |
756 TreeNode versionNode = treeNode.getParent(); |
753 TreeNode versionNode = treeNode.getParent(); |
757 TreeNode familyNode = versionNode.getParent(); |
754 TreeNode familyNode = versionNode.getParent(); |
758 if (pair.equals(new Pair(familyNode.getValue(), versionNode.getValue()))) |
755 if (ObjectUtils.equals(pair.first, familyNode.getValue()) && |
|
756 ObjectUtils.equals(pair.second, versionNode.getValue())) |
759 return treeNode; |
757 return treeNode; |
760 } |
758 } |
761 TreeNode[] children = treeNode.getChildren(); |
759 TreeNode[] children = treeNode.getChildren(); |
762 if (children != null) { |
760 if (children != null) { |
763 TreeNode treeNodeFromChildren = findTreeNodeForPair(children, pair); |
761 TreeNode treeNodeFromChildren = findTreeNodeForPair(children, pair); |
784 if (newConnection || connectedService == null || !connectedService.getService().equals(service)) { |
782 if (newConnection || connectedService == null || !connectedService.getService().equals(service)) { |
785 disposeConnectedService(); |
783 disposeConnectedService(); |
786 connectedService = |
784 connectedService = |
787 Registry.instance().createConnectedService(service, connection); |
785 Registry.instance().createConnectedService(service, connection); |
788 IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection(); |
786 IStructuredSelection selection = (IStructuredSelection) deviceOSComboViewer.getSelection(); |
789 Pair<String, Version> pair = (Pair<String, Version>) selection.getFirstElement(); |
787 Pair<String, String> pair = (Pair<String, String>) selection.getFirstElement(); |
790 if (pair != null) |
788 if (pair != null && connectedService instanceof IConnectedService2) { |
791 connectedService.setDeviceOS(pair.first, pair.second); |
789 ((IConnectedService2) connectedService).setDeviceOS(pair.first, pair.second); |
|
790 } |
792 connectedService.addStatusChangedListener(statusListener = new IStatusChangedListener() { |
791 connectedService.addStatusChangedListener(statusListener = new IStatusChangedListener() { |
793 public void statusChanged(final IStatus status) { |
792 public void statusChanged(final IStatus status) { |
794 Display.getDefault().asyncExec(new Runnable() { |
793 Display.getDefault().asyncExec(new Runnable() { |
795 public void run() { |
794 public void run() { |
796 if (!statusText.isDisposed()) |
795 if (!statusText.isDisposed()) |
897 return (TreeNode[]) sdkFamilyToNodes.values().toArray(new TreeNode[sdkFamilyToNodes.values().size()]); |
896 return (TreeNode[]) sdkFamilyToNodes.values().toArray(new TreeNode[sdkFamilyToNodes.values().size()]); |
898 } |
897 } |
899 |
898 |
900 private void createFamilySubNodes(TreeNode familyNode, IRemoteAgentInstallerProvider installerProvider) { |
899 private void createFamilySubNodes(TreeNode familyNode, IRemoteAgentInstallerProvider installerProvider) { |
901 String familyName = familyNode.getValue().toString(); |
900 String familyName = familyNode.getValue().toString(); |
902 List<Version> versions = installerProvider.getVersions(familyName); |
901 List<String> versions = installerProvider.getVersions(familyName); |
903 List<TreeNode> childList = new ArrayList<TreeNode>(); |
902 List<TreeNode> childList = new ArrayList<TreeNode>(); |
904 TreeNode[] children = familyNode.getChildren(); |
903 TreeNode[] children = familyNode.getChildren(); |
905 if (children != null) |
904 if (children != null) |
906 childList.addAll(Arrays.asList(children)); |
905 childList.addAll(Arrays.asList(children)); |
907 for (Version version : versions) { |
906 for (String version : versions) { |
908 TreeNode versionNode = getVersionNode(familyNode, version); |
907 TreeNode versionNode = getVersionNode(familyNode, version); |
909 if (versionNode == null) { |
908 if (versionNode == null) { |
910 versionNode = new TreeNode(version); |
909 versionNode = new TreeNode(version); |
911 versionNode.setParent(familyNode); |
910 versionNode.setParent(familyNode); |
912 childList.add(versionNode); |
911 childList.add(versionNode); |
914 createInstallerNodes(versionNode, installerProvider); |
913 createInstallerNodes(versionNode, installerProvider); |
915 } |
914 } |
916 familyNode.setChildren((TreeNode[]) childList.toArray(new TreeNode[childList.size()])); |
915 familyNode.setChildren((TreeNode[]) childList.toArray(new TreeNode[childList.size()])); |
917 } |
916 } |
918 |
917 |
919 private TreeNode getVersionNode(TreeNode familyNode, Version version) { |
918 private TreeNode getVersionNode(TreeNode familyNode, String version) { |
920 TreeNode[] children = familyNode.getChildren(); |
919 TreeNode[] children = familyNode.getChildren(); |
921 if (children != null) { |
920 if (children != null) { |
922 for (TreeNode node : children) { |
921 for (TreeNode node : children) { |
923 if (node.getValue().equals(version)) |
922 if (node.getValue().equals(version)) |
924 return node; |
923 return node; |
927 return null; |
926 return null; |
928 } |
927 } |
929 |
928 |
930 private void createInstallerNodes(TreeNode versionNode, IRemoteAgentInstallerProvider installerProvider) { |
929 private void createInstallerNodes(TreeNode versionNode, IRemoteAgentInstallerProvider installerProvider) { |
931 String familyName = versionNode.getParent().getValue().toString(); |
930 String familyName = versionNode.getParent().getValue().toString(); |
932 Version version = (Version) versionNode.getValue(); |
931 String version = versionNode.getValue().toString(); |
933 List<IRemoteAgentInstaller> installers = |
932 List<IRemoteAgentInstaller> installers = |
934 installerProvider.getRemoteAgentInstallers(familyName, version); |
933 installerProvider.getRemoteAgentInstallers(familyName, version); |
935 List<TreeNode> childList = new ArrayList<TreeNode>(); |
934 List<TreeNode> childList = new ArrayList<TreeNode>(); |
936 TreeNode[] children = versionNode.getChildren(); |
935 TreeNode[] children = versionNode.getChildren(); |
937 if (children != null) |
936 if (children != null) |
942 childList.add(installerNode); |
941 childList.add(installerNode); |
943 } |
942 } |
944 versionNode.setChildren((TreeNode[]) childList.toArray(new TreeNode[childList.size()])); |
943 versionNode.setChildren((TreeNode[]) childList.toArray(new TreeNode[childList.size()])); |
945 } |
944 } |
946 |
945 |
947 private synchronized List<Pair<String, Version>> createDeviceOSPairs() { |
946 private synchronized List<Pair<String, String>> createDeviceOSPairs() { |
948 List<Pair<String, Version>> deviceOSPairs = new ArrayList<Pair<String, Version>>(); |
947 List<Pair<String, String>> deviceOSPairs = new ArrayList<Pair<String, String>>(); |
949 for (IRemoteAgentInstallerProvider installerProvider : installerProviders) { |
948 for (IRemoteAgentInstallerProvider installerProvider : installerProviders) { |
950 List<String> familyNames = installerProvider.getSDKFamilyNames(null); |
949 List<String> familyNames = installerProvider.getSDKFamilyNames(null); |
951 for (String familyName : familyNames) { |
950 for (String familyName : familyNames) { |
952 List<Version> versions = installerProvider.getVersions(familyName); |
951 List<String> versions = installerProvider.getVersions(familyName); |
953 for (Version version : versions) { |
952 for (String version : versions) { |
954 Pair<String, Version> pair = new Pair<String, Version>(familyName, version); |
953 Pair<String, String> pair = new Pair<String, String>(familyName, version); |
955 if (!deviceOSPairs.contains(pair)) |
954 if (!deviceOSPairs.contains(pair)) |
956 deviceOSPairs.add(pair); |
955 deviceOSPairs.add(pair); |
957 } |
956 } |
958 } |
957 } |
959 } |
958 } |