Skip to main content
summaryrefslogtreecommitdiffstats
blob: bb4c0319a2b178669497566ff533aef9afd39b82 (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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*******************************************************************************
 * Copyright (c) 2018 Remain Software
 * 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:
 *     wim.jongman@remainsoftware.com - initial API and implementation
 *******************************************************************************/
package org.eclipse.tips.manual.tests;

import java.net.MalformedURLException;

import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.swt.graphics.DeviceData;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.tips.core.ITipManager;
import org.eclipse.tips.core.JsonTestProvider;
import org.eclipse.tips.core.Tip;
import org.eclipse.tips.core.TipProvider;
import org.eclipse.tips.core.internal.TipManager;
import org.eclipse.tips.ui.internal.TipDialog;
import org.eclipse.tips.ui.internal.util.ResourceManager;
import org.eclipse.tips.ui.internal.util.SWTResourceManager;

/**
 * Class to manage the tip providers and start the tip of the day UI.
 */
@SuppressWarnings("restriction")
public class SleakTipManager extends TipManager {

	private static SleakTipManager instance = new SleakTipManager();

	public static void main(String[] args) throws MalformedURLException {
		instance.register(new JsonTestProvider());
		if (!instance.getProviders().isEmpty()) {
			instance.open(true);
		}
	}

	/**
	 * @return the tip manager instance.
	 */
	public static SleakTipManager getInstance() {
		return instance;
	}

	private SleakTipManager() {
	}

	/**
	 * For resource leak detection rename this method to open and run the IDE. Won't
	 * work on Linux because GTK cannot handle multiple displays.
	 */
	@Override
	public TipManager open(boolean pStart) {

		Thread t = new Thread(() -> {

			DeviceData data = new DeviceData();
			data.tracking = true;
			Display display = new Display(data);
			new Sleak().open();
			TipDialog tipDialog = new TipDialog(null, SleakTipManager.this, TipDialog.DEFAULT_STYLE, null);
			tipDialog.open();
			Shell shell = tipDialog.getShell();
			shell.addDisposeListener(pE -> dispose());
			shell.pack();
			shell.open();
			while (!display.isDisposed()) {
				if (!display.readAndDispatch()) {
					display.sleep();
				}
			}
			display.dispose();
		});

		t.start();
		return this;

	}

	@Override
	public ITipManager register(TipProvider provider) {
		super.register(provider);
		load(provider);
		return this;
	}

	private void load(TipProvider pProvider) {
		pProvider.loadNewTips(new NullProgressMonitor());
	}

	@Override
	public boolean isRead(Tip pTip) {
		return false;
	}

	@Override
	public TipManager setAsRead(Tip pTip) {
		return this;
	}

	protected synchronized SleakTipManager setNewTips(boolean pNewTips) {
		return this;
	}

	@Override
	public void dispose() {
		SWTResourceManager.dispose();
		ResourceManager.dispose();
		super.dispose();
	}

	@Override
	public TipManager setStartupBehavior(int pStartupBehavior) {
		return this;
	}

	@Override
	public ITipManager log(IStatus pStatus) {
		return this;
	}

	@Override
	public int getPriority(TipProvider pProvider) {
		return 0;
	}
}

Back to the top