remove ui dependency + use new notification to switch mode RCL_2_4
authordadubrow
Fri, 26 Feb 2010 11:31:16 -0600
branchRCL_2_4
changeset 1035 a50c0b5d243e
parent 1034 42eaaa076776
child 1038 03399a178bc5
remove ui dependency + use new notification to switch mode
connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/META-INF/MANIFEST.MF
connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Activator.java
connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Messages.java
connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/messages.properties
connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/pccsnative/PCCSConnection.java
--- a/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/META-INF/MANIFEST.MF	Fri Feb 26 11:30:21 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/META-INF/MANIFEST.MF	Fri Feb 26 11:31:16 2010 -0600
@@ -7,8 +7,6 @@
 Bundle-Vendor: Nokia
 Require-Bundle: org.eclipse.cdt.core,
  org.eclipse.core.runtime,
- org.eclipse.jface,
- org.eclipse.ui,
  com.nokia.carbide.remoteConnections
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
--- a/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Activator.java	Fri Feb 26 11:30:21 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Activator.java	Fri Feb 26 11:31:16 2010 -0600
@@ -17,9 +17,7 @@
 package com.nokia.carbide.remoteconnections.discovery.pccs;
 
 import org.eclipse.core.runtime.Platform;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.eclipse.core.runtime.Plugin;
 import org.osgi.framework.BundleContext;
 
 import com.nokia.cpp.internal.api.utils.core.Logging;
@@ -27,7 +25,7 @@
 /**
  * The activator class controls the plug-in life cycle
  */
-public class Activator extends AbstractUIPlugin {
+public class Activator extends Plugin {
 
 	// The plug-in ID
 	public static final String PLUGIN_ID = "com.nokia.carbide.remoteConnections.discovery.pccs"; //$NON-NLS-1$
@@ -96,8 +94,4 @@
 	public static void logMessage(String message, int type) {
 		Logging.log(plugin, Logging.newStatus(plugin, type, message));
 	}
-
-	public static void setHelp(Control control, String id) {
-		PlatformUI.getWorkbench().getHelpSystem().setHelp(control, PLUGIN_ID + id);		 //$NON-NLS-1$
-	}
 }
--- a/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Messages.java	Fri Feb 26 11:30:21 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Messages.java	Fri Feb 26 11:31:16 2010 -0600
@@ -37,11 +37,6 @@
 	public static String PCCSConnection_PCCS_Version_Error;
 	public static String PCCSConnection_PCSuite_Version_Error;
 	public static String PCCSConnection_Personality_Switch_Error;
-	public static String PCCSConnection_Switch_Message_Title;
-	public static String PCCSConnection_Switch_Message1;
-	public static String PCCSConnection_Switch_Message3;
-	public static String PCCSConnection_Switch_Message4;
-	public static String PCCSConnection_Swtich_Message2;
 	public static String PCCSDiscoveryAgent_PCCS_Not_Found_Error;
 	public static String PCCSDiscoveryAgent_PCCS_Version_Error;
 	public static String PCCSDiscoveryAgent_PCSuite_Not_Found_Error;
--- a/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/messages.properties	Fri Feb 26 11:30:21 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/messages.properties	Fri Feb 26 11:31:16 2010 -0600
@@ -15,11 +15,6 @@
 PCCSConnection_PCCS_Version_Error=The requested PC Connectivity Solution DMAPI version (3.4) is not installed on this machine. To install a later version go to: 
 PCCSConnection_PCSuite_Version_Error=The current PC Suite intallation does not support the required level of API for this agent. To install a later version go to: 
 PCCSConnection_Personality_Switch_Error=Connected device "{0}" does not support getting/setting the USB personality from the current personality.
-PCCSConnection_Switch_Message_Title=Switch Device USB Personality
-PCCSConnection_Switch_Message1=The "{0}" device is currently in "{1}" USB personality, which is not compatible with on-device debugging. 
-PCCSConnection_Switch_Message3=Click Yes to switch to the latter personality and create a remote connection.\nClick No to leave the device in the current personality and 
-PCCSConnection_Switch_Message4=not create a connection.\n\nTo not see this reminder again, check the "Don''t ask again" box.
-PCCSConnection_Swtich_Message2=This device supports the "{2}" debugging compatible personality.\n\n
 PCCSDiscoveryAgent_PCCS_Not_Found_Error=Agent could not find the PC Connectivity Solution (PCCS) installation.
 PCCSDiscoveryAgent_PCCS_Version_Error=Agent requires a later version of the PC Connectivity Solution (PCCS) installed.
 PCCSDiscoveryAgent_PCSuite_Not_Found_Error=Agent could not find a PC Suite installation.
--- a/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/pccsnative/PCCSConnection.java	Fri Feb 26 11:30:21 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/pccsnative/PCCSConnection.java	Fri Feb 26 11:31:16 2010 -0600
@@ -29,17 +29,11 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Status;
-import org.eclipse.core.runtime.preferences.InstanceScope;
-import org.eclipse.jface.dialogs.IDialogConstants;
-import org.eclipse.jface.dialogs.MessageDialogWithToggle;
-import org.eclipse.swt.widgets.Display;
-import org.osgi.service.prefs.BackingStoreException;
 
+import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
 import com.nokia.carbide.remoteconnections.discovery.pccs.Activator;
 import com.nokia.carbide.remoteconnections.discovery.pccs.Messages;
 import com.nokia.carbide.remoteconnections.discovery.pccs.pccsnative.IConnAPILibrary.IConnAPIDeviceCallback;
-import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
-
 import com.sun.jna.Pointer;
 import com.sun.jna.WString;
 import com.sun.jna.ptr.IntByReference;
@@ -49,11 +43,7 @@
 
 	private static final String NOT_KNOWN = "not known"; //$NON-NLS-1$ // used for all string structure elements that come back from PCCS as null
 	private boolean DEBUG = false;
-	private String DONT_ASK_AGAIN_KEY = "DontAskAgain"; //$NON-NLS-1$
 	
-	/**
-	 *
-	 */
 	public class DeviceNotificationCallback implements IConnAPIDeviceCallback {
 
 		/* (non-Javadoc)
@@ -114,23 +104,9 @@
 	private APIHANDLE dmHandle = APIHANDLE.INVALID_HANDLE_VALUE;
 	private APIHANDLE mcHandle = APIHANDLE.INVALID_HANDLE_VALUE;
 	private APIHANDLE upHandle = APIHANDLE.INVALID_HANDLE_VALUE;
-	private boolean dontAskAgain;
-	private boolean doSwitch;
 	
 	private Collection<String> noSwitchConnections = new ArrayList<String>();
 	
-	private void storeDontAskAgain() {
-		Activator.getDefault().getPreferenceStore().setValue(DONT_ASK_AGAIN_KEY, true);
-		try {
-			new InstanceScope().getNode(Activator.PLUGIN_ID).flush();
-		} catch (BackingStoreException e) {
-			Activator.logError(e);
-		}
-	}
-	private boolean dontAskAgain() {
-		return Activator.getDefault().getPreferenceStore().getBoolean(DONT_ASK_AGAIN_KEY);
-	}
-
 	public PCCSConnection() {
 	}
 
@@ -352,14 +328,14 @@
 	
 	private void terminateDMAPI() {
     	// Terminate Device management API
-    	int dwResult = library.DMAPI_Terminate(null);
+    	/*int dwResult =*/ library.DMAPI_Terminate(null);
 		if (DEBUG) System.out.println("terminateDMAPI"); //$NON-NLS-1$
 	}
 	private void stopDMNotifications(APIHANDLE handle) {
-		int dwResult = PCCSErrors.CONA_OK;
+//		int dwResult = PCCSErrors.CONA_OK;
 		if (!APIHANDLE.INVALID_HANDLE_VALUE.equals(handle)) {
 			// unregister callback
-			dwResult = library.CONARegisterNotifyCallback(handle, PCCSTypeDefinitions.API_UNREGISTER, pfnCallback);
+			/*dwResult =*/ library.CONARegisterNotifyCallback(handle, PCCSTypeDefinitions.API_UNREGISTER, pfnCallback);
 		}		
 		if (DEBUG) System.out.println("stopDMNotifications"); //$NON-NLS-1$
 	}
@@ -379,13 +355,13 @@
 	}
 
 	private void closeMCAPI() {
-		int dwResult = PCCSErrors.CONA_OK;
+//		int dwResult = PCCSErrors.CONA_OK;
 		if (!APIHANDLE.INVALID_HANDLE_VALUE.equals(mcHandle)) {
 			// close DM connection
-			dwResult = library.CONACloseDM(mcHandle);
+			/*dwResult =*/ library.CONACloseDM(mcHandle);
 			mcHandle = APIHANDLE.INVALID_HANDLE_VALUE;
         	// Terminate Device management API
-    		dwResult = library.MCAPI_Terminate(null);
+    		/*dwResult =*/ library.MCAPI_Terminate(null);
 		}
 		if (DEBUG) System.out.println("closeMCAPI----\n"); //$NON-NLS-1$
 	}
@@ -667,7 +643,7 @@
 			if (DEBUG) System.out.println("forgetAllNoSwitchConnectionsNotInCurrentList: noSwitchConnections already empty");
 				return;
 		} else {
-			for (String id : noSwitchConnections) {
+			for (String id : new ArrayList<String>(noSwitchConnections)) {
 				boolean found = false;
 				for (DeviceUSBPersonalityInfo personality : personalityList) {
 					if (id.equals(personality.deviceID)) {
@@ -768,15 +744,6 @@
 		}
 		String goodDesc = personality.supportedPersonalities.get(new Integer(goodCode));
 
-		if (dontAskAgain()) {
-			if (DEBUG) System.out.println("isGoodUSBPersonality: dont ask = true, return false"); //$NON-NLS-1$
-			String fmt = Messages.PCCSConnection_Bad_Personality_DontSwitch_Warning1 +
-			Messages.PCCSConnection_Bad_Personality_DontSwitch_Warning2;
-			String message = MessageFormat.format(fmt, device.friendlyName, personality.currentPersonalityDescription, goodDesc);
-			Activator.logMessage(message, IStatus.WARNING);
-			return false;
-		}
-
 		if (!noSwitchConnectionsContains(personality.deviceID))
 			// ask to switch
 			askToSwitchPersonality(device, personality, goodCode, goodDesc);
@@ -812,65 +779,37 @@
 			if (DEBUG) System.out.println("forgetNoSwitchConnections empty");
 			return;
 		}
-		for (String id : noSwitchConnections) {
-			if (id.equals(deviceID)) {
-				if (DEBUG) System.out.println("forgetNoSwitchConnections: " + deviceID);
-				noSwitchConnections.remove(deviceID);
-			}
-		}
+		if (DEBUG) System.out.println("forgetNoSwitchConnections: " + deviceID);
+		noSwitchConnections.remove(deviceID);
 	}
+	
 	private void askToSwitchPersonality(final DeviceInfo device,
 			final DeviceUSBPersonalityInfo personality, final int goodCode, final String goodDesc) {
 		
-		doSwitch = false;
-		Display.getDefault().syncExec(
-			new Runnable() {
+		// remember this device so we don't ask again unless it changes personality or is reconnected
+		rememberNoSwitchConnections(personality.deviceID);
 
-				public void run() {
-					// ask the user and switch
-					String fmt = Messages.PCCSConnection_Switch_Message1 +
-					Messages.PCCSConnection_Swtich_Message2 +
-					Messages.PCCSConnection_Switch_Message3 +
-					Messages.PCCSConnection_Switch_Message4;
-					String message = MessageFormat.format(fmt,
-							device.friendlyName,
-							personality.currentPersonalityDescription,
-							goodDesc);
-
-					MessageDialogWithToggle dlg = MessageDialogWithToggle.openYesNoQuestion(
-							WorkbenchUtils.getSafeShell(), 
-							Messages.PCCSConnection_Switch_Message_Title, 
-							message, 
-							Messages.PCCSConnection_DontAsk_CheckText, 
-							false, 
-							null, 
-							null);
-					dontAskAgain = dlg.getToggleState();
-					doSwitch = (dlg.getReturnCode() == IDialogConstants.YES_ID);
-					
+		String message = MessageFormat.format(
+				"''{0}'' is currently in {1} mode\nand must be in {2} mode to be usable in Carbide.",
+				device.friendlyName,
+				personality.currentPersonalityDescription,
+				goodDesc);
+		IStatus status = new Status(IStatus.WARNING, Activator.PLUGIN_ID, message);
+		
+		String prompt = MessageFormat.format("Switch to {0} mode now.", goodDesc);
+		
+		RemoteConnectionsActivator.getStatusDisplay().displayStatusWithAction(status, prompt, new Runnable() {
+			public void run() {
+				WString pstrDeviceId = new WString(personality.deviceID);
+				int dwResult = library.UPAPI_SetPersonality(upHandle, pstrDeviceId, goodCode);
+				if (dwResult != PCCSErrors.CONA_OK) {
+					forgetNoSwitchConnections(personality.deviceID);
+					if (DEBUG)
+						System.out.printf("UPAPI_SetPersonality failed: %x\n", dwResult); //$NON-NLS-1$
 				}
 			}
-		);
-		if (doSwitch) {
-			WString pstrDeviceId = new WString(personality.deviceID);
-			int dwResult = library.UPAPI_SetPersonality(upHandle, pstrDeviceId, goodCode);
-			if (dwResult != PCCSErrors.CONA_OK) {
-				if (DEBUG)
-					System.out.printf("UPAPI_SetPersonality failed: %x\n", dwResult); //$NON-NLS-1$
-			}
-		} else {
-			// remember this device so we don't ask again unless it changes personality or is reconnected
-			rememberNoSwitchConnections(personality.deviceID);
-			// also log an info message to error log regarding this
-			String fmt = Messages.PCCSConnection_Switch_Message1 + Messages.PCCSConnection_Swtich_Message2;
-			String message = MessageFormat.format(fmt, 	device.friendlyName,
-							personality.currentPersonalityDescription,
-							goodDesc);
-			Activator.logMessage(message, IStatus.INFO);
-		}
-		// store don't ask again only if selected
-		if (dontAskAgain)
-			storeDontAskAgain();
+		});
+
 	}
 
 	/**
@@ -1017,10 +956,10 @@
 	}
 
 
-	private String getBTComPort(String address) {
-		// TODO Auto-generated method stub
-		return null;
-	}
+//	private String getBTComPort(String address) {
+//		// TODO Auto-generated method stub
+//		return null;
+//	}
 
 	public String getUSBComPort(String address) {
 		if (address != null && address.length() > 0) {