tweaks to new discovery error dialog and calling code
authordadubrow
Mon, 01 Feb 2010 13:12:03 -0600
changeset 856 74d8d653d11a
parent 854 a7d9320cd85e
child 865 ed312e9f8961
tweaks to new discovery error dialog and calling code
connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java
connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceDiscoveryPrequisiteErrorDialog.java
connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties
--- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java	Mon Feb 01 11:12:20 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/discovery/RandomDiscoveryAgent.java	Mon Feb 01 13:12:03 2010 -0600
@@ -17,6 +17,7 @@
 
 package com.nokia.carbide.remoteconnections.tests.discovery;
 
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.util.HashSet;
 import java.util.Map;
@@ -37,25 +38,26 @@
 public class RandomDiscoveryAgent implements IDeviceDiscoveryAgent {
 	public class RandomPrerequisiteStatus implements IPrerequisiteStatus {
 
-		private boolean OK;
-		private String errorText;
-		private URL location;
+		private boolean ok;
 		
 		RandomPrerequisiteStatus() {
-			OK = true;
-			errorText = null;
-			location = null;
+			ok = true; // modify to test
 		}
 		public String getErrorText() {
-			return errorText;
+			return "Test error text";
 		}
 
 		public URL getURL() {
-			return location;
+			try {
+				return new URL("http://www.yahoo.com");
+			} catch (MalformedURLException e) {
+				e.printStackTrace();
+			}
+			return null;
 		}
 
 		public boolean isOK() {
-			return OK;
+			return ok;
 		}
 
 	}
@@ -117,7 +119,6 @@
 		connection.setDynamic(true);
 		connections.add(connection);
 		manager.addConnection(connection);
-		manager.setCurrentConnection(connection);
 	}
 
 	private String getRandomIntervalString() {
--- a/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java	Mon Feb 01 11:12:20 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections.tests/src/com/nokia/carbide/remoteconnections/tests/extensions/RandomCycleConnectedService.java	Mon Feb 01 13:12:03 2010 -0600
@@ -18,19 +18,27 @@
 
 package com.nokia.carbide.remoteconnections.tests.extensions;
 
-import com.nokia.carbide.remoteconnections.interfaces.*;
-import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
-import com.nokia.cpp.internal.api.utils.core.Check;
-import com.nokia.cpp.internal.api.utils.core.ListenerList;
+import java.text.DateFormat;
+import java.util.Date;
+import java.util.Random;
 
 import org.eclipse.jface.action.IStatusLineManager;
 import org.eclipse.swt.widgets.Display;
-import org.eclipse.ui.*;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
 import org.osgi.framework.Version;
 
-import java.text.DateFormat;
-import java.util.Date;
-import java.util.Random;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService;
+import com.nokia.carbide.remoteconnections.interfaces.IConnection;
+import com.nokia.carbide.remoteconnections.interfaces.IService;
+import com.nokia.carbide.remoteconnections.interfaces.IConnectedService.IStatus.EStatus;
+import com.nokia.cpp.internal.api.utils.core.ListenerList;
 
 public class RandomCycleConnectedService implements IConnectedService {
 	
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java	Mon Feb 01 11:12:20 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/RemoteConnectionsActivator.java	Mon Feb 01 13:12:03 2010 -0600
@@ -18,18 +18,22 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IConfigurationElement;
 import org.eclipse.core.runtime.IStatus;
 import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.preferences.InstanceScope;
 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.ui.PlatformUI;
 import org.eclipse.ui.plugin.AbstractUIPlugin;
 import org.osgi.framework.BundleContext;
+import org.osgi.service.prefs.BackingStoreException;
 
 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider;
 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager;
@@ -38,6 +42,7 @@
 import com.nokia.carbide.remoteconnections.internal.registry.Registry;
 import com.nokia.carbide.remoteconnections.internal.ui.DeviceDiscoveryPrequisiteErrorDialog;
 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;
 
 /**
@@ -48,14 +53,12 @@
 	// The plug-in ID
 	public static final String PLUGIN_ID = "com.nokia.carbide.remoteConnections"; //$NON-NLS-1$
 
-	private static final String DISCOVERY_AGENT_EXTENSION = 
-		PLUGIN_ID + ".deviceDiscoveryAgent"; //$NON-NLS-1$
+	private static final String DISCOVERY_AGENT_EXTENSION = PLUGIN_ID + ".deviceDiscoveryAgent"; //$NON-NLS-1$
 
 	// The shared instance
 	private static RemoteConnectionsActivator plugin;
 
 	private Collection<IDeviceDiscoveryAgent> discoveryAgents;
-	private boolean ignoreAgentLoadErrors = false;
 	private static final String IGNORE_AGENT_LOAD_ERRORS_KEY = "ignoreAgentLoadErrors"; //$NON-NLS-1$
 
 	/**
@@ -71,74 +74,63 @@
 		instance.loadExtensions();
 		instance.loadConnections();
 
-		loadIgnoreAgentLoadErrorsFlag();
-		if (!ignoreAgentLoadErrors) {
-			checkPrerequisites();
-			// loading done in checkPrerequisites after load errors dealt with
-		} else {
-			// if we ignore the load errors
-			// go ahead and load anyway
-			loadAndStartDeviceDiscoveryAgents();
-		}
+		RunRunnableWhenWorkbenchVisibleJob.start(new Runnable() {
+			public void run() {
+				if (!ignoreAgentLoadErrors())
+					checkPrerequisites();
+
+				loadAndStartDeviceDiscoveryAgents();
+			}
+		});
 	}
 
-	private void loadIgnoreAgentLoadErrorsFlag() {
-		ignoreAgentLoadErrors = getPreferenceStore().getBoolean(IGNORE_AGENT_LOAD_ERRORS_KEY);
+	private boolean ignoreAgentLoadErrors() {
+		return getPreferenceStore().getBoolean(IGNORE_AGENT_LOAD_ERRORS_KEY);
 	}
 
 	private void checkPrerequisites() {
-		final Collection<String> agentNames = new ArrayList<String>();
-		final Collection<IPrerequisiteStatus> agentStatuses = new ArrayList<IPrerequisiteStatus>();
+		final Map<IDeviceDiscoveryAgent, IPrerequisiteStatus> agentToStatusMap = 
+			new HashMap<IDeviceDiscoveryAgent, IPrerequisiteStatus>();
+		
 		// load the extensions just to check statuses
-		// later we'll load them for real
 		Collection<IDeviceDiscoveryAgent> agents = new ArrayList<IDeviceDiscoveryAgent>();
-		
 		loadExtensions(DISCOVERY_AGENT_EXTENSION, null, agents, null);
 		
 		for (IDeviceDiscoveryAgent agent : agents) {
 			IPrerequisiteStatus status = agent.getPrerequisiteStatus();
 			if (!status.isOK()) {
-				agentNames.add(agent.getDisplayName());
-				agentStatuses.add(status);
+				agentToStatusMap.put(agent, status);
 			}
 		}
 
-		if (!agentNames.isEmpty()) {
-			Display.getDefault().asyncExec(new Runnable() {
-
-				public void run() {
-					DeviceDiscoveryPrequisiteErrorDialog dlg = new DeviceDiscoveryPrequisiteErrorDialog(WorkbenchUtils.getSafeShell());
-					IPrerequisiteStatus[] statuses = (IPrerequisiteStatus[]) agentStatuses.toArray(new IPrerequisiteStatus[agentStatuses.size()]);
-					String[] names = agentNames.toArray(new String[agentNames.size()]);
-					for (int i = 0; i < names.length; i++) {
-						dlg.addAgentData(names[i], statuses[i].getErrorText(), statuses[i].getURL());
-					}
-					dlg.open();
-					ignoreAgentLoadErrors = dlg.isDontBotherMeOn();
-					dlg.close();
-					
-					// now load and start agents for real
-					loadAndStartDeviceDiscoveryAgents();
-				}
-			});
-		} else {
-			// now load and start agents for real
-			loadAndStartDeviceDiscoveryAgents();
-		}
+		if (!agentToStatusMap.isEmpty()) {
+			DeviceDiscoveryPrequisiteErrorDialog dlg = new DeviceDiscoveryPrequisiteErrorDialog(WorkbenchUtils.getSafeShell());
+			for (Entry<IDeviceDiscoveryAgent, IPrerequisiteStatus> entry : agentToStatusMap.entrySet()) {
+				IDeviceDiscoveryAgent agent = entry.getKey();
+				IPrerequisiteStatus status = entry.getValue();
+				dlg.addAgentData(agent.getDisplayName(), status.getErrorText(), status.getURL());
+			}
+			dlg.open();
+			if (dlg.isDontAskAgainChecked())
+				storeIgnoreAgentLoadErrorsFlag();
+		}	
 	}
 
 	public void stop(BundleContext context) throws Exception {
 		stopDeviceDiscoveryAgents();
 		Registry.instance().storeConnections();
 		Registry.instance().disposeConnections();
-		storeIgnoreAgentLoadErrorsFlag();
 		plugin = null;
 		super.stop(context);
 	}
 
 	private void storeIgnoreAgentLoadErrorsFlag() {
-		getPreferenceStore().setValue(IGNORE_AGENT_LOAD_ERRORS_KEY, ignoreAgentLoadErrors);
-		savePluginPreferences();
+		getPreferenceStore().setValue(IGNORE_AGENT_LOAD_ERRORS_KEY, true);
+		try {
+			new InstanceScope().getNode(PLUGIN_ID).flush();
+		} catch (BackingStoreException e) {
+			logError(e);
+		}
 	}
 
 	/**
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceDiscoveryPrequisiteErrorDialog.java	Mon Feb 01 11:12:20 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/internal/ui/DeviceDiscoveryPrequisiteErrorDialog.java	Mon Feb 01 13:12:03 2010 -0600
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
 * All rights reserved.
 * This component and the accompanying materials are made available
 * under the terms of the License "Eclipse Public License v1.0"
@@ -17,11 +17,12 @@
 package com.nokia.carbide.remoteconnections.internal.ui;
 
 import java.net.URL;
+import java.text.MessageFormat;
 import java.util.ArrayList;
 import java.util.Collection;
 
-import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.TrayDialog;
 import org.eclipse.jface.viewers.ArrayContentProvider;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.ISelectionChangedListener;
@@ -51,9 +52,10 @@
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.browser.IWebBrowser;
 
+import com.nokia.carbide.remoteconnections.Messages;
 import com.nokia.carbide.remoteconnections.RemoteConnectionsActivator;
 
-public class DeviceDiscoveryPrequisiteErrorDialog extends Dialog {
+public class DeviceDiscoveryPrequisiteErrorDialog extends TrayDialog {
 
 	private class AgentItem {
 		public String agentName;
@@ -66,19 +68,19 @@
 			agentLocation = location;
 			// if location is not null and error text doesn't contain href
 			//  then do it here
-			if (agentLocation != null && !agentErrorText.contains("href=")) {
-				String msg = String.format("%s - For more information go to: <a href=\"%s\">%s</a>",
-						agentErrorText, location.toString(), location.toString());
+			if (agentLocation != null && !agentErrorText.contains("href")) { //$NON-NLS-1$
+				String msg = MessageFormat.format(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ErrorFormatWithURL"), //$NON-NLS-1$
+						agentErrorText, location, location);
 				agentErrorText = msg;
 			}
 		}
 	}
 	
 	private Collection<AgentItem> agentList = new ArrayList<AgentItem>();
-	private boolean isDontBotherMeOn = false;
+	private boolean dontAskAgain;
 	private ListViewer agentListViewer;
 	private Link errorText;
-	private Button dontBotherMeCheckBox;
+	private Button dontAskAgainCheckBox;
 
 	/**
 	 * @param parentShell
@@ -100,8 +102,8 @@
 		agentList.add(new AgentItem(name, errorText, location));
 	}
 
-	public boolean isDontBotherMeOn() {
-		return isDontBotherMeOn;
+	public boolean isDontAskAgainChecked() {
+		return dontAskAgain;
 	}
 
 	@Override
@@ -122,20 +124,18 @@
 	
 		// Message at top
 		Text topMessage = new Text(container, SWT.MULTI | SWT.WRAP);
-		topMessage.setText("At least one device discovery agent had load errors that prevent it from discovering connections to devices. Select one to get more information about its error.");
+		topMessage.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_Description")); //$NON-NLS-1$
 		topMessage.setEditable(false);
 		topMessage.setDoubleClickEnabled(false);
 		GridData topMsgData = new GridData(SWT.LEFT, SWT.CENTER, true, false);
 		topMsgData.heightHint = 48;
 		topMessage.setLayoutData(topMsgData);
-		topMessage.setToolTipText("Select an agent for more information about load errors.");
+		topMessage.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ToolTipText")); //$NON-NLS-1$
 
 		// next two panes can be resized with a sash form
 		SashForm sashForm = new SashForm(container, SWT.VERTICAL);
 		GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
 		sashForm.setLayoutData(gridData);
-		sashForm.setToolTipText("Slide to adjust pane size above and below to see more text.");
-		
 
 		// this pane lists all the agent display names
 		agentListViewer = new ListViewer(sashForm, SWT.V_SCROLL | SWT.BORDER);
@@ -162,7 +162,7 @@
 		// pane to view the information about the selected agent
 		errorText = new Link(sashForm, SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
 		errorText.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
-		errorText.setToolTipText("Error message for the selected agent above");
+		errorText.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_ErrorTextToolTipText")); //$NON-NLS-1$
 		errorText.addListener(SWT.Selection, new Listener() {
 
 			public void handleEvent(Event event) {
@@ -182,16 +182,15 @@
 		// add initial weights to the above two panes
 		sashForm.setWeights(new int[] {150,200});
 
-		// now the don't bother me check box
-		dontBotherMeCheckBox = new Button(container, SWT.CHECK);
-		dontBotherMeCheckBox.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
-		dontBotherMeCheckBox.setText("Don't bother me again.");
-		dontBotherMeCheckBox.setToolTipText("Check this to ignore further discovery agent load errors");
-		dontBotherMeCheckBox.setSelection(isDontBotherMeOn);
-		dontBotherMeCheckBox.addSelectionListener(new SelectionAdapter() {
+		// now the don't ask again check box
+		dontAskAgainCheckBox = new Button(container, SWT.CHECK);
+		dontAskAgainCheckBox.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, false));
+		dontAskAgainCheckBox.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainLabel")); //$NON-NLS-1$
+		dontAskAgainCheckBox.setToolTipText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainToolTipText")); //$NON-NLS-1$
+		dontAskAgainCheckBox.addSelectionListener(new SelectionAdapter() {
 
 			public void widgetSelected(SelectionEvent e) {
-				isDontBotherMeOn = dontBotherMeCheckBox.getSelection();
+				dontAskAgain = dontAskAgainCheckBox.getSelection();
 			}
 
 		});
@@ -216,15 +215,9 @@
 	}
 
 	@Override
-	protected void okPressed() {
-		// TODO Auto-generated method stub
-		super.okPressed();
-	}
-
-	@Override
 	protected void configureShell(Shell newShell) {
 		super.configureShell(newShell);
 		// set our title to the dialog
-		newShell.setText("Device Discovery Load Errors");
+		newShell.setText(Messages.getString("DeviceDiscoveryPrequisiteErrorDialog_Title")); //$NON-NLS-1$
 	}
 }
--- a/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Mon Feb 01 11:12:20 2010 -0600
+++ b/connectivity/com.nokia.carbide.remoteConnections/src/com/nokia/carbide/remoteconnections/messages.properties	Mon Feb 01 13:12:03 2010 -0600
@@ -81,6 +81,13 @@
 ConnectionStatusSelectorContribution.NoDynamicOrManualConnectionsTooltip=No current connection selected.
 ConnectionStatusSelectorContribution.NotInUse=Not in use
 ConnectionStatusSelectorContribution.StatusFormat=Connection is {0}: {1}
+DeviceDiscoveryPrequisiteErrorDialog_Description=At least one device discovery agent had load errors that prevent it from discovering connections to devices. Select one to get more information about its error.
+DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainLabel=Don't ask again
+DeviceDiscoveryPrequisiteErrorDialog_DontAskAgainToolTipText=Check this to ignore further discovery agent load errors
+DeviceDiscoveryPrequisiteErrorDialog_ErrorFormatWithURL={0} - For more information go to: <a href="{1}">{2}</a>
+DeviceDiscoveryPrequisiteErrorDialog_ErrorTextToolTipText=Error message for the selected agent above
+DeviceDiscoveryPrequisiteErrorDialog_Title=Device Discovery Load Errors
+DeviceDiscoveryPrequisiteErrorDialog_ToolTipText=Select an agent for more information about load errors.
 ExportPage.BrowseGroupLabel=Connections file:
 ExportPage.Description=Select connections to export
 ExportPage.FileDialogTitle=Save As