Skip to main content
summaryrefslogtreecommitdiffstats
blob: 456cfc7a31e30ad7090d8445be69bf0bdf737e6b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*******************************************************************************
 * Copyright (c) 2004, 2008 Tasktop Technologies and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Tasktop Technologies - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.examples.monitor.study;

import org.eclipse.jdt.internal.ui.JavaPlugin;
import org.eclipse.mylyn.internal.monitor.ui.MonitorUiPlugin;
import org.eclipse.mylyn.internal.monitor.usage.UiUsageMonitorPlugin;
import org.eclipse.pde.internal.ui.PDEPlugin;
import org.eclipse.ui.IStartup;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchPlugin;
import org.eclipse.ui.internal.editors.text.EditorsPlugin;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.BundleContext;

/**
 * @author Mik Kersten
 */
public class MylynUserStudyExamplePlugin extends AbstractUIPlugin {

	public static final String ID_PLUGIN = "org.eclipse.mylyn.examples.monitor.study";

	private static MylynUserStudyExamplePlugin plugin;

	private SelectionMonitor selectionMonitor;

	public MylynUserStudyExamplePlugin() {
		plugin = this;
	}

	public static class MylynUserStudyExampleStartup implements IStartup {

		public void earlyStartup() {
			final IWorkbench workbench = PlatformUI.getWorkbench();
			workbench.getDisplay().asyncExec(new Runnable() {
				public void run() {
					MylynUserStudyExamplePlugin.getDefault().selectionMonitor = new SelectionMonitor();
					MonitorUiPlugin.getDefault()
							.getSelectionMonitors()
							.add(MylynUserStudyExamplePlugin.getDefault().selectionMonitor);

					UiUsageMonitorPlugin.getDefault().addMonitoredPreferences(
							WorkbenchPlugin.getDefault().getPreferenceStore());
					UiUsageMonitorPlugin.getDefault().addMonitoredPreferences(
							JavaPlugin.getDefault().getPreferenceStore());
					UiUsageMonitorPlugin.getDefault().addMonitoredPreferences(
							WorkbenchPlugin.getDefault().getPreferenceStore());
					UiUsageMonitorPlugin.getDefault().addMonitoredPreferences(
							EditorsPlugin.getDefault().getPreferenceStore());
					UiUsageMonitorPlugin.getDefault().addMonitoredPreferences(
							PDEPlugin.getDefault().getPreferenceStore());
				}
			});
		}
	}

	@Override
	public void start(BundleContext context) throws Exception {
		super.start(context);
	}

	@Override
	public void stop(BundleContext context) throws Exception {
		super.stop(context);
		plugin = null;

		MonitorUiPlugin.getDefault().getSelectionMonitors().remove(selectionMonitor);
		UiUsageMonitorPlugin.getDefault().removeMonitoredPreferences(WorkbenchPlugin.getDefault().getPreferenceStore());
		UiUsageMonitorPlugin.getDefault().removeMonitoredPreferences(JavaPlugin.getDefault().getPreferenceStore());
		UiUsageMonitorPlugin.getDefault().removeMonitoredPreferences(WorkbenchPlugin.getDefault().getPreferenceStore());
		UiUsageMonitorPlugin.getDefault().removeMonitoredPreferences(EditorsPlugin.getDefault().getPreferenceStore());
		UiUsageMonitorPlugin.getDefault().removeMonitoredPreferences(PDEPlugin.getDefault().getPreferenceStore());
	}

	/**
	 * Returns the shared instance.
	 */
	public static MylynUserStudyExamplePlugin getDefault() {
		return plugin;
	}

}

Back to the top