Add support for status notification popups and remove ui dependency + use new notification to switch mode
authordadubrow
Mon, 01 Mar 2010 07:58:33 -0600
changeset 1037 7261015324d2
parent 1036 b1909e47f4af
child 1039 c7873299d91f
Add support for status notification popups and 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
connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java
--- a/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/META-INF/MANIFEST.MF	Fri Feb 26 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/META-INF/MANIFEST.MF	Mon Mar 01 07:58:33 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 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Activator.java	Mon Mar 01 07:58:33 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 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/Messages.java	Mon Mar 01 07:58:33 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 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/messages.properties	Mon Mar 01 07:58:33 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 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.discovery.pccs/src/com/nokia/carbide/remoteconnections/discovery/pccs/pccsnative/PCCSConnection.java	Mon Mar 01 07:58:33 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$
 	}
@@ -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 : new ArrayList<String>(noSwitchConnections)) {
-			if (id.equals(deviceID)) {
-				if (DEBUG) System.out.println("forgetNoSwitchConnections: " + deviceID);
-				noSwitchConnections.remove(id);
-			}
-		}
+		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) {
--- a/connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF	Fri Feb 26 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/META-INF/MANIFEST.MF	Mon Mar 01 07:58:33 2010 -0600
@@ -7,11 +7,12 @@
 Bundle-Vendor: Nokia
 Bundle-Localization: plugin
 Require-Bundle: org.eclipse.core.runtime,
- org.eclipse.ui,
+ org.eclipse.ui;visibility:=reexport,
  com.nokia.cpp.utils.core,
  org.eclipse.emf.ecore.xmi;bundle-version="2.4.0",
  org.eclipse.core.net;bundle-version="1.1.0",
- com.nokia.cpp.utils.ui
+ com.nokia.cpp.utils.ui,
+ org.eclipse.mylyn.commons.ui
 Bundle-RequiredExecutionEnvironment: J2SE-1.5
 Bundle-ActivationPolicy: lazy
 Export-Package: com.nokia.carbide.installpackages,
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java	Fri Feb 26 15:49:28 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java	Mon Mar 01 07:58:33 2010 -0600
@@ -30,6 +30,8 @@
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.jface.viewers.IFilter;
 import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
@@ -38,11 +40,12 @@
 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
 import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent;
+import com.nokia.carbide.remoteconnections.internal.api.IStatusDisplay;
 import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent.IPrerequisiteStatus;
 import com.nokia.carbide.remoteconnections.internal.registry.Registry;
 import com.nokia.carbide.remoteconnections.internal.ui.DeviceDiscoveryPrequisiteErrorDialog;
+import com.nokia.carbide.remoteconnections.internal.ui.StatusDisplay;
 import com.nokia.cpp.internal.api.utils.core.Logging;
-import com.nokia.cpp.internal.api.utils.ui.RunRunnableWhenWorkbenchVisibleJob;
 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils;
 
 /**
@@ -50,6 +53,39 @@
  */
 public class RemoteConnectionsActivator extends AbstractUIPlugin {
 
+	private final class WhenWorkbenchIsVisibleThread extends Thread {
+		private Shell shell;
+		private boolean visible;
+		private final Runnable runnable;
+		
+		public WhenWorkbenchIsVisibleThread(Runnable runnable) {
+			this.runnable = runnable;
+			shell = WorkbenchUtils.getActiveShell();
+		}
+		
+		public void run() {
+			while (true) {
+				Display.getDefault().syncExec(new Runnable() {
+					public void run() {
+						if (shell != null && shell.isVisible()) {
+							visible = true;
+						}
+					}
+				});
+				if (visible)
+					break;
+				
+				try {
+					Thread.sleep(500);
+				} catch (InterruptedException e) {
+					break;
+				}
+			}
+			if (visible)
+				runnable.run();
+		}
+	}
+
 	// The plug-in ID
 	public static final String PLUGIN_ID = "com.nokia.carbide.remoteConnections"; //$NON-NLS-1$
 
@@ -59,6 +95,7 @@
 	private static RemoteConnectionsActivator plugin;
 
 	private Collection<IDeviceDiscoveryAgent> discoveryAgents;
+
 	private static final String IGNORE_AGENT_LOAD_ERRORS_KEY = "ignoreAgentLoadErrors"; //$NON-NLS-1$
 
 	/**
@@ -74,14 +111,14 @@
 		instance.loadExtensions();
 		instance.loadConnections();
 
-		RunRunnableWhenWorkbenchVisibleJob.start(new Runnable() {
+		new WhenWorkbenchIsVisibleThread(new Runnable() {
 			public void run() {
 				if (!ignoreAgentLoadErrors())
 					checkPrerequisites();
-
+				
 				loadAndStartDeviceDiscoveryAgents();
 			}
-		});
+		}).start();
 	}
 
 	private boolean ignoreAgentLoadErrors() {
@@ -242,4 +279,8 @@
 			}
 		}
 	}
+	
+	public static IStatusDisplay getStatusDisplay() {
+		return new StatusDisplay();
+	}
 }