Skip to main content
summaryrefslogtreecommitdiffstats
blob: 525b5b245b95bbdda3d7a9dca59d4c5a16f19b0b (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
/*******************************************************************************
 * 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.examples.tipsframework;

import java.awt.Desktop;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.tips.core.IHtmlTip;
import org.eclipse.tips.core.Tip;
import org.eclipse.tips.core.TipAction;
import org.eclipse.tips.core.TipImage;
import org.eclipse.tips.examples.DateUtil;

public class GithubTip extends Tip implements IHtmlTip {

	public GithubTip(String providerId) {
		super(providerId);
	}

	@Override
	public List<TipAction> getActions() {
		Runnable runner = () -> Display.getDefault().asyncExec(() -> {
			if (Platform.isRunning() && Platform.getWS().startsWith("gtk")) {
				MessageDialog.openInformation(null, "Action", "Can't open a browser in GTK. It crashes the JVM.");
			} else {
				Desktop d = Desktop.getDesktop();
				try {
					d.browse(new URI("https://github.com/wimjongman/tips"));
				} catch (IOException | URISyntaxException e) {
					e.printStackTrace();
				}
			}
		});

		ArrayList<TipAction> actions = new ArrayList<>();
		actions.add(new TipAction("Show in Github", "Opens a browser.", runner, null));
		return actions;
	}

	@Override
	public Date getCreationDate() {
		return DateUtil.getDateFromYYMMDD("09/01/2018");
	}

	@Override
	public String getSubject() {
		return "On GitHub";
	}

	@Override
	public String getHTML() {
		return "<h2>Incubating on GitHub</h2>We are incubating this project on Github "
				+ "and we could use your help. Press the <b>More...</b> button to open the " + "GitHub repository. "
				+ "<br>" + "<br>" + "We are looking forward to your pull requests." + "<br>";
	}

	private TipImage fImage;

	@Override
	public TipImage getImage() {
		if (fImage == null) {
			try {
				fImage = new TipImage(new URL("https://assets-cdn.github.com/images/modules/logos_page/Octocat.png"))
						.setAspectRatio(800, 665, true);
			} catch (Exception e) {
//				getProvider().getManager().log(LogUtil.error(getClass(), e));
			}
		}
		return fImage;
	}
}

Back to the top