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
|
/*******************************************************************************
* 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.internal.github.ui.gist;
import java.text.MessageFormat;
import org.eclipse.egit.github.core.Gist;
import org.eclipse.mylyn.commons.ui.dialogs.AbstractNotificationPopup;
import org.eclipse.mylyn.internal.github.ui.GitHubImages;
import org.eclipse.mylyn.internal.tasks.core.AbstractTask;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
/**
* Gist notification popup class
*/
@SuppressWarnings("restriction")
public class GistNotificationPopup extends AbstractNotificationPopup {
private Gist gist;
private String title;
private TaskRepository repository;
/**
* Create Gist notification popup
*
* @param display
* @param gist
* @param title
* @param repository
*/
public GistNotificationPopup(Display display, Gist gist, String title,
TaskRepository repository) {
super(display);
this.gist = gist;
this.title = title;
this.repository = repository;
}
@Override
protected void createContentArea(Composite composite) {
composite.setLayout(new GridLayout(1, true));
Label label = new Label(composite, SWT.NONE);
label.setText(MessageFormat.format(
Messages.GistNotificationPopup_GistTitle, title));
Link link = new Link(composite, SWT.WRAP);
link.setText(MessageFormat.format(
Messages.GistNotificationPopup_GistLink, gist.getId()));
link.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
link.setBackground(composite.getBackground());
link.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
AbstractTask task = TasksUiInternal.getTask(
repository.getRepositoryUrl(), gist.getId(),
gist.getHtmlUrl());
if (task != null)
TasksUiInternal.refreshAndOpenTaskListElement(task);
else
TasksUiInternal.openTask(repository, gist.getId(), null);
}
});
}
@Override
protected String getPopupShellTitle() {
return Messages.GistNotificationPopup_ShellTitle;
}
@Override
protected Image getPopupShellImage(int maximumHeight) {
return GitHubImages.get(GitHubImages.GITHUB_LOGO_OBJ);
}
}
|