Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fcc4e567e934294ebeb0b930478b82a2c0c8e8a5 (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
/*******************************************************************************
 * Copyright (c) 2011 Red Hat 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:
 *     Chris Aniszczyk <caniszczyk@gmail.com> - initial contribution
 *******************************************************************************/
package org.eclipse.mylyn.github.ui.internal;

import java.io.IOException;
import java.util.Collections;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.mylyn.github.internal.Gist;
import org.eclipse.mylyn.github.internal.GistFile;
import org.eclipse.mylyn.github.internal.GistService;
import org.eclipse.mylyn.github.internal.User;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PlatformUI;

public class CreateGistJob extends Job {

	private String title;
	private String extension;
	private String content;
	private GistService service;
	private String user;

	public CreateGistJob(String name, String title, String content,
			GistService service, String user) {
		super(name);
		this.title = title;
		this.content = content;
		this.service = service;
		this.user = user;
	}

	@Override
	protected IStatus run(IProgressMonitor monitor) {
		try {
			Gist gist = new Gist().setPublic(true);
			if (user != null)
				gist.setUser(new User().setLogin(user));
			gist.setDescription(title);
			GistFile file = new GistFile().setContent(content);
			gist.setFiles(Collections.singletonMap(title, file));
			final Gist created = service.createGist(gist);
			PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
				@SuppressWarnings("restriction")
				public void run() {
					GistNotificationPopup popup = new GistNotificationPopup(
							PlatformUI.getWorkbench().getDisplay(), created, title);
					popup.create();
					popup.open();
				}
			});
		} catch (IOException e) {
			GitHubUi.logError(e);
		}
		return Status.OK_STATUS;
	}
}

Back to the top