28 import org.eclipse.core.runtime.Platform; |
28 import org.eclipse.core.runtime.Platform; |
29 import org.eclipse.core.runtime.preferences.InstanceScope; |
29 import org.eclipse.core.runtime.preferences.InstanceScope; |
30 import org.eclipse.jface.resource.ImageDescriptor; |
30 import org.eclipse.jface.resource.ImageDescriptor; |
31 import org.eclipse.jface.viewers.IFilter; |
31 import org.eclipse.jface.viewers.IFilter; |
32 import org.eclipse.swt.widgets.Control; |
32 import org.eclipse.swt.widgets.Control; |
|
33 import org.eclipse.swt.widgets.Display; |
|
34 import org.eclipse.swt.widgets.Shell; |
33 import org.eclipse.ui.PlatformUI; |
35 import org.eclipse.ui.PlatformUI; |
34 import org.eclipse.ui.plugin.AbstractUIPlugin; |
36 import org.eclipse.ui.plugin.AbstractUIPlugin; |
35 import org.osgi.framework.BundleContext; |
37 import org.osgi.framework.BundleContext; |
36 import org.osgi.service.prefs.BackingStoreException; |
38 import org.osgi.service.prefs.BackingStoreException; |
37 |
39 |
38 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
40 import com.nokia.carbide.remoteconnections.interfaces.IConnectionTypeProvider; |
39 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
41 import com.nokia.carbide.remoteconnections.interfaces.IConnectionsManager; |
40 import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent; |
42 import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent; |
|
43 import com.nokia.carbide.remoteconnections.internal.api.IStatusDisplay; |
41 import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent.IPrerequisiteStatus; |
44 import com.nokia.carbide.remoteconnections.internal.api.IDeviceDiscoveryAgent.IPrerequisiteStatus; |
42 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
45 import com.nokia.carbide.remoteconnections.internal.registry.Registry; |
43 import com.nokia.carbide.remoteconnections.internal.ui.DeviceDiscoveryPrequisiteErrorDialog; |
46 import com.nokia.carbide.remoteconnections.internal.ui.DeviceDiscoveryPrequisiteErrorDialog; |
|
47 import com.nokia.carbide.remoteconnections.internal.ui.StatusDisplay; |
44 import com.nokia.cpp.internal.api.utils.core.Logging; |
48 import com.nokia.cpp.internal.api.utils.core.Logging; |
45 import com.nokia.cpp.internal.api.utils.ui.RunRunnableWhenWorkbenchVisibleJob; |
|
46 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
49 import com.nokia.cpp.internal.api.utils.ui.WorkbenchUtils; |
47 |
50 |
48 /** |
51 /** |
49 * The activator class controls the plug-in life cycle |
52 * The activator class controls the plug-in life cycle |
50 */ |
53 */ |
51 public class RemoteConnectionsActivator extends AbstractUIPlugin { |
54 public class RemoteConnectionsActivator extends AbstractUIPlugin { |
52 |
55 |
|
56 private final class WhenWorkbenchIsVisibleThread extends Thread { |
|
57 private Shell shell; |
|
58 private boolean visible; |
|
59 private final Runnable runnable; |
|
60 |
|
61 public WhenWorkbenchIsVisibleThread(Runnable runnable) { |
|
62 this.runnable = runnable; |
|
63 shell = WorkbenchUtils.getActiveShell(); |
|
64 } |
|
65 |
|
66 public void run() { |
|
67 while (true) { |
|
68 Display.getDefault().syncExec(new Runnable() { |
|
69 public void run() { |
|
70 if (shell != null && shell.isVisible()) { |
|
71 visible = true; |
|
72 } |
|
73 } |
|
74 }); |
|
75 if (visible) |
|
76 break; |
|
77 |
|
78 try { |
|
79 Thread.sleep(500); |
|
80 } catch (InterruptedException e) { |
|
81 break; |
|
82 } |
|
83 } |
|
84 if (visible) |
|
85 runnable.run(); |
|
86 } |
|
87 } |
|
88 |
53 // The plug-in ID |
89 // The plug-in ID |
54 public static final String PLUGIN_ID = "com.nokia.carbide.remoteConnections"; //$NON-NLS-1$ |
90 public static final String PLUGIN_ID = "com.nokia.carbide.remoteConnections"; //$NON-NLS-1$ |
55 |
91 |
56 private static final String DISCOVERY_AGENT_EXTENSION = PLUGIN_ID + ".deviceDiscoveryAgent"; //$NON-NLS-1$ |
92 private static final String DISCOVERY_AGENT_EXTENSION = PLUGIN_ID + ".deviceDiscoveryAgent"; //$NON-NLS-1$ |
57 |
93 |
58 // The shared instance |
94 // The shared instance |
59 private static RemoteConnectionsActivator plugin; |
95 private static RemoteConnectionsActivator plugin; |
60 |
96 |
61 private Collection<IDeviceDiscoveryAgent> discoveryAgents; |
97 private Collection<IDeviceDiscoveryAgent> discoveryAgents; |
|
98 |
62 private static final String IGNORE_AGENT_LOAD_ERRORS_KEY = "ignoreAgentLoadErrors"; //$NON-NLS-1$ |
99 private static final String IGNORE_AGENT_LOAD_ERRORS_KEY = "ignoreAgentLoadErrors"; //$NON-NLS-1$ |
63 |
100 |
64 /** |
101 /** |
65 * The constructor |
102 * The constructor |
66 */ |
103 */ |
72 plugin = this; |
109 plugin = this; |
73 Registry instance = Registry.instance(); |
110 Registry instance = Registry.instance(); |
74 instance.loadExtensions(); |
111 instance.loadExtensions(); |
75 instance.loadConnections(); |
112 instance.loadConnections(); |
76 |
113 |
77 RunRunnableWhenWorkbenchVisibleJob.start(new Runnable() { |
114 new WhenWorkbenchIsVisibleThread(new Runnable() { |
78 public void run() { |
115 public void run() { |
79 if (!ignoreAgentLoadErrors()) |
116 if (!ignoreAgentLoadErrors()) |
80 checkPrerequisites(); |
117 checkPrerequisites(); |
81 |
118 |
82 loadAndStartDeviceDiscoveryAgents(); |
119 loadAndStartDeviceDiscoveryAgents(); |
83 } |
120 } |
84 }); |
121 }).start(); |
85 } |
122 } |
86 |
123 |
87 private boolean ignoreAgentLoadErrors() { |
124 private boolean ignoreAgentLoadErrors() { |
88 return getPreferenceStore().getBoolean(IGNORE_AGENT_LOAD_ERRORS_KEY); |
125 return getPreferenceStore().getBoolean(IGNORE_AGENT_LOAD_ERRORS_KEY); |
89 } |
126 } |