connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/settings/ui/ConnectionSettingsPage.java
changeset 44 e4eb00aa1a3f
parent 2 d760517a8095
child 55 8254273d11c0
equal deleted inserted replaced
43:dc139699a5b0 44:e4eb00aa1a3f
    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.interfaces.IConnectedService.IStatus;
    24 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus;
    25 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
    25 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatusChangedListener;
       
    26 import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
    26 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory.IValidationErrorReporter;
    27 import com.nokia.carbide.remoteconnections.interfaces.IConnectionFactory.IValidationErrorReporter;
    27 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller;
    28 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller;
    28 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller.IPackageContents;
    29 import com.nokia.carbide.remoteconnections.interfaces.IRemoteAgentInstallerProvider.IRemoteAgentInstaller.IPackageContents;
    29 import com.nokia.cpp.internal.api.utils.core.*;
    30 import com.nokia.cpp.internal.api.utils.core.*;
    30 
    31 
    53 import java.text.MessageFormat;
    54 import java.text.MessageFormat;
    54 import java.util.*;
    55 import java.util.*;
    55 import java.util.List;
    56 import java.util.List;
    56 
    57 
    57 public class ConnectionSettingsPage extends WizardPage {
    58 public class ConnectionSettingsPage extends WizardPage {
       
    59 	
       
    60 	public final class Tester extends Thread {
       
    61 		@Override
       
    62 		public void run() {
       
    63 			((AbstractConnectedService) connectedService).setManualTesting();
       
    64 			for (int i = 0; i < 3 && connectedService != null; i++) {
       
    65 				connectedService.testStatus();
       
    66 				try {
       
    67 					if (i < 2)
       
    68 						sleep(AbstractConnectedService.TIMEOUT);
       
    69 				} catch (InterruptedException e) {
       
    70 					break;
       
    71 				}
       
    72 			}
       
    73 			resetServiceTesting(false);
       
    74 		}
       
    75 	}
    58 
    76 
    59 	private final static TreeNode LOADING_CONTENT_TREENODE = 
    77 	private final static TreeNode LOADING_CONTENT_TREENODE = 
    60 		new TreeNode(Messages.getString("ConnectionSettingsPage.GettingDataMessage")); //$NON-NLS-1$
    78 		new TreeNode(Messages.getString("ConnectionSettingsPage.GettingDataMessage")); //$NON-NLS-1$
    61 	private static final String STATUS_NOT_TESTED = 
    79 	private static final String STATUS_NOT_TESTED = 
    62 		Messages.getString("ConnectionSettingsPage.NotTestedStatusString"); //$NON-NLS-1$
    80 		Messages.getString("ConnectionSettingsPage.NotTestedStatusString"); //$NON-NLS-1$
    76 	private Label statusLabel;
    94 	private Label statusLabel;
    77 	private Text statusText;
    95 	private Text statusText;
    78 	private IConnectionFactory connectionFactory;
    96 	private IConnectionFactory connectionFactory;
    79 	private IConnection connection;
    97 	private IConnection connection;
    80 	private IService service;
    98 	private IService service;
    81 	private IConnectedService connectedService;
    99 	private volatile IConnectedService connectedService;
    82 	private IStatusChangedListener statusListener;
   100 	private IStatusChangedListener statusListener;
       
   101 	private Tester tester;
    83 	private SashForm installerSashForm;
   102 	private SashForm installerSashForm;
    84 	private TreeViewer installerTreeViewer;
   103 	private TreeViewer installerTreeViewer;
    85 	private Text installerInfoText;
   104 	private Text installerInfoText;
    86 	private Button installerSaveButton;
   105 	private Button installerSaveButton;
    87 	private Button installButton;
   106 	private Button installButton;
   199 			public void selectionChanged(SelectionChangedEvent event) {
   218 			public void selectionChanged(SelectionChangedEvent event) {
   200 				IStructuredSelection selection = (IStructuredSelection) servicesListViewer.getSelection();
   219 				IStructuredSelection selection = (IStructuredSelection) servicesListViewer.getSelection();
   201 				IService curService = (IService) selection.getFirstElement();
   220 				IService curService = (IService) selection.getFirstElement();
   202 				if (!curService.equals(service)) {
   221 				if (!curService.equals(service)) {
   203 					service = curService;
   222 					service = curService;
   204 					resetServiceTesting();
   223 					resetServiceTesting(true);
   205 				}
   224 				}
   206 			}
   225 			}
   207 		});
   226 		});
   208 		servicesListViewer.getControl().setToolTipText(Messages.getString("ConnectionSettingsPage.ServicesListToolTip")); //$NON-NLS-1$
   227 		servicesListViewer.getControl().setToolTipText(Messages.getString("ConnectionSettingsPage.ServicesListToolTip")); //$NON-NLS-1$
   209 		servicesListViewer.getControl().setData(UID, "servicesListViewer"); //$NON-NLS-1$
   228 		servicesListViewer.getControl().setData(UID, "servicesListViewer"); //$NON-NLS-1$
   228 		serviceTestButton.addSelectionListener(new SelectionAdapter() {
   247 		serviceTestButton.addSelectionListener(new SelectionAdapter() {
   229 			@Override
   248 			@Override
   230 			public void widgetSelected(SelectionEvent e) {
   249 			public void widgetSelected(SelectionEvent e) {
   231 				if (isTesting) {
   250 				if (isTesting) {
   232 					serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
   251 					serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel")); //$NON-NLS-1$
   233 					resetServiceTesting();
   252 					resetServiceTesting(true);
   234 				}
   253 				}
   235 				else {
   254 				else {
   236 					serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StopServiceTestButtonLabel")); //$NON-NLS-1$
   255 					serviceTestButton.setText(Messages.getString("ConnectionSettingsPage.StopServiceTestButtonLabel")); //$NON-NLS-1$
   237 					testService();
   256 					testService();
   238 				}
   257 				}
   441 				servicesListViewer.getList().select(0);
   460 				servicesListViewer.getList().select(0);
   442 				servicesListViewer.setSelection(servicesListViewer.getSelection());
   461 				servicesListViewer.setSelection(servicesListViewer.getSelection());
   443 			}
   462 			}
   444 			servicesListViewer.getList().addFocusListener(new FocusAdapter() {
   463 			servicesListViewer.getList().addFocusListener(new FocusAdapter() {
   445 				public void focusGained(FocusEvent e) {
   464 				public void focusGained(FocusEvent e) {
   446 					resetServiceTesting();
   465 					resetServiceTesting(true);
   447 				}
   466 				}
   448 			});
   467 			});
   449 			
   468 			
   450 			Thread t = new Thread() {
   469 			Thread t = new Thread() {
   451 				@Override
   470 				@Override
   503 					deviceOSComboViewer.getCombo().select(0);
   522 					deviceOSComboViewer.getCombo().select(0);
   504 					deviceOSComboViewer.getCombo().setEnabled(false);
   523 					deviceOSComboViewer.getCombo().setEnabled(false);
   505 				}
   524 				}
   506 				deviceOSComboViewer.getCombo().addFocusListener(new FocusAdapter() {
   525 				deviceOSComboViewer.getCombo().addFocusListener(new FocusAdapter() {
   507 					public void focusGained(FocusEvent e) {
   526 					public void focusGained(FocusEvent e) {
   508 						resetServiceTesting();
   527 						resetServiceTesting(true);
   509 					}
   528 					}
   510 				});
   529 				});
   511 			}
   530 			}
   512 		});
   531 		});
   513 
   532 
   566 				public void statusChanged(final IStatus status) {
   585 				public void statusChanged(final IStatus status) {
   567 					Display.getDefault().asyncExec(new Runnable() {
   586 					Display.getDefault().asyncExec(new Runnable() {
   568 						public void run() {
   587 						public void run() {
   569 							if (!statusText.isDisposed())
   588 							if (!statusText.isDisposed())
   570 								statusText.setText(status.getLongDescription());
   589 								statusText.setText(status.getLongDescription());
       
   590 							if (status.getEStatus().equals(EStatus.UP))
       
   591 								resetServiceTesting(false);
   571 						}
   592 						}
   572 					});
   593 					});
   573 				}
   594 				}
   574 			});
   595 			});
   575 			if (connectedService instanceof AbstractConnectedService)
   596 			if (connectedService instanceof AbstractConnectedService)
   576 				((AbstractConnectedService) connectedService).setRunnableContext(getContainer());
   597 				((AbstractConnectedService) connectedService).setRunnableContext(getContainer());
   577 			connectedService.setEnabled(true);
   598 			tester = new Tester();
       
   599 			tester.start();
   578 			isTesting = true;
   600 			isTesting = true;
   579 		}
   601 		}
   580 	}
   602 	}
   581 
   603 
   582 	@Override
   604 	@Override
   762 			installerProviders.clear();
   784 			installerProviders.clear();
   763 			installerProviders = null;
   785 			installerProviders = null;
   764 		}
   786 		}
   765 	}
   787 	}
   766 	
   788 	
   767 	private void resetServiceTesting() {
   789 	private void resetServiceTesting(final boolean resetAll) {
   768 		isTesting = false;
   790 		isTesting = false;
   769 		if (service == null)
   791 		if (service == null)
   770 			return;
   792 			return;
   771 		serviceTestInfo.setText(service.getAdditionalServiceInfo());
   793 		// may be called from a test thread
   772 		agentTestTabComposite.layout(true, true);
   794 		Display.getDefault().syncExec(new Runnable() {
   773 		statusText.setText(STATUS_NOT_TESTED);
   795 			public void run() {
   774 		disposeConnectedService();
   796 				if (resetAll) {
   775 		String buttonLabel = Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel"); //$NON-NLS-1$
   797 					statusText.setText(STATUS_NOT_TESTED);
   776 		serviceTestButton.setText(buttonLabel);
   798 					serviceTestInfo.setText(service.getAdditionalServiceInfo());
       
   799 					agentTestTabComposite.layout(true, true);
       
   800 				}
       
   801 				disposeConnectedService();
       
   802 				String buttonLabel = Messages.getString("ConnectionSettingsPage.StartServiceTestButtonLabel"); //$NON-NLS-1$
       
   803 				serviceTestButton.setText(buttonLabel);
       
   804 			}
       
   805 		});
   777 	}
   806 	}
   778 
   807 
   779 }
   808 }