Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2010 Tasktop Technologies and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Eclipse Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/epl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* Tasktop Technologies - initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.mylyn.internal.tasks.ui.notifications; |
13 |
|
14 |
import org.eclipse.jface.dialogs.Dialog; |
15 |
import org.eclipse.jface.layout.GridDataFactory; |
16 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
17 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes; |
18 |
import org.eclipse.mylyn.internal.provisional.commons.ui.GradientCanvas; |
19 |
import org.eclipse.mylyn.internal.tasks.core.servicemessage.IServiceMessageListener; |
20 |
import org.eclipse.mylyn.internal.tasks.core.servicemessage.ServiceMessage; |
21 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; |
22 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
23 |
import org.eclipse.mylyn.tasks.ui.TasksUiUtil; |
24 |
import org.eclipse.swt.SWT; |
25 |
import org.eclipse.swt.events.DisposeEvent; |
26 |
import org.eclipse.swt.events.DisposeListener; |
27 |
import org.eclipse.swt.graphics.Color; |
28 |
import org.eclipse.swt.graphics.Font; |
29 |
import org.eclipse.swt.graphics.FontData; |
30 |
import org.eclipse.swt.graphics.Image; |
31 |
import org.eclipse.swt.layout.GridData; |
32 |
import org.eclipse.swt.layout.GridLayout; |
33 |
import org.eclipse.swt.widgets.Composite; |
34 |
import org.eclipse.swt.widgets.Control; |
35 |
import org.eclipse.swt.widgets.Display; |
36 |
import org.eclipse.swt.widgets.Label; |
37 |
import org.eclipse.ui.PlatformUI; |
38 |
import org.eclipse.ui.forms.FormColors; |
39 |
import org.eclipse.ui.forms.IFormColors; |
40 |
import org.eclipse.ui.forms.events.HyperlinkAdapter; |
41 |
import org.eclipse.ui.forms.events.HyperlinkEvent; |
42 |
import org.eclipse.ui.forms.events.IHyperlinkListener; |
43 |
import org.eclipse.ui.forms.widgets.Hyperlink; |
44 |
import org.eclipse.ui.forms.widgets.ImageHyperlink; |
45 |
|
46 |
/** |
47 |
* @author Robert Elves |
48 |
*/ |
49 |
public class TaskListServiceMessageControl implements IServiceMessageListener { |
50 |
|
51 |
private ImageHyperlink imageHyperlink; |
52 |
|
53 |
private Hyperlink titleHyperlink; |
54 |
|
55 |
private Label descriptionLabel; |
56 |
|
57 |
private GridData headData; |
58 |
|
59 |
private final Composite parent; |
60 |
|
61 |
private GradientCanvas head; |
62 |
|
63 |
private ImageHyperlink closeLink; |
64 |
|
65 |
private ServiceMessage currentMessage; |
66 |
|
67 |
private boolean constructed; |
68 |
|
69 |
private String messageUrl; |
70 |
|
71 |
public TaskListServiceMessageControl(Composite parent) { |
72 |
this.parent = parent; |
73 |
createControl(parent); |
74 |
} |
75 |
|
76 |
private void setTitleImage(Image image) { |
77 |
imageHyperlink.setImage(image); |
78 |
} |
79 |
|
80 |
private void setTitle(String title) { |
81 |
titleHyperlink.setText(title); |
82 |
} |
83 |
|
84 |
private void setDescription(String description) { |
85 |
descriptionLabel.setText(description); |
86 |
} |
87 |
|
88 |
private void addHyperlinkListener(IHyperlinkListener listener) { |
89 |
titleHyperlink.addHyperlinkListener(listener); |
90 |
imageHyperlink.addHyperlinkListener(listener); |
91 |
} |
92 |
|
93 |
protected void setMessageUrl(String url) { |
94 |
messageUrl = url; |
95 |
} |
96 |
|
97 |
public Control createControl(Composite parent) { |
98 |
FormColors colors = new FormColors(parent.getDisplay()); |
99 |
head = new GradientCanvas(parent, SWT.NONE); |
100 |
GridLayout headLayout = new GridLayout(); |
101 |
headLayout.marginHeight = 0; |
102 |
headLayout.marginWidth = 0; |
103 |
headLayout.horizontalSpacing = 0; |
104 |
headLayout.verticalSpacing = 0; |
105 |
headLayout.numColumns = 1; |
106 |
head.setLayout(headLayout); |
107 |
headData = new GridData(SWT.FILL, SWT.TOP, true, false); |
108 |
head.setLayoutData(headData); |
109 |
setHidden(true); |
110 |
|
111 |
Color top = colors.getColor(IFormColors.H_GRADIENT_END); |
112 |
Color bot = colors.getColor(IFormColors.H_GRADIENT_START); |
113 |
head.setBackgroundGradient(new Color[] { bot, top }, new int[] { 100 }, true); |
114 |
head.setSeparatorVisible(true); |
115 |
head.setSeparatorAlignment(SWT.TOP); |
116 |
|
117 |
head.putColor(IFormColors.H_BOTTOM_KEYLINE1, colors.getColor(IFormColors.H_BOTTOM_KEYLINE1)); |
118 |
head.putColor(IFormColors.H_BOTTOM_KEYLINE2, colors.getColor(IFormColors.H_BOTTOM_KEYLINE2)); |
119 |
head.putColor(IFormColors.H_HOVER_LIGHT, colors.getColor(IFormColors.H_HOVER_LIGHT)); |
120 |
head.putColor(IFormColors.H_HOVER_FULL, colors.getColor(IFormColors.H_HOVER_FULL)); |
121 |
head.putColor(IFormColors.TB_TOGGLE, colors.getColor(IFormColors.TB_TOGGLE)); |
122 |
head.putColor(IFormColors.TB_TOGGLE_HOVER, colors.getColor(IFormColors.TB_TOGGLE_HOVER)); |
123 |
|
124 |
Composite informationComp = new Composite(head, SWT.NONE); |
125 |
informationComp.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));//new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL)); |
126 |
informationComp.setLayout(new GridLayout(3, false)); |
127 |
|
128 |
imageHyperlink = new ImageHyperlink(informationComp, SWT.NONE); |
129 |
|
130 |
titleHyperlink = new Hyperlink(informationComp, SWT.WRAP); |
131 |
setHeaderFontSizeAndStyle(titleHyperlink); |
132 |
|
133 |
addHyperlinkListener(new HyperlinkAdapter() { |
134 |
@Override |
135 |
public void linkActivated(HyperlinkEvent e) { |
136 |
if (messageUrl != null) { |
137 |
TasksUiUtil.openUrl(messageUrl); |
138 |
} |
139 |
|
140 |
} |
141 |
}); |
142 |
|
143 |
closeLink = new ImageHyperlink(informationComp, SWT.NONE); |
144 |
closeLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_CLOSE)); |
145 |
GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).applyTo(closeLink); |
146 |
closeLink.addHyperlinkListener(new HyperlinkAdapter() { |
147 |
@Override |
148 |
public void linkActivated(HyperlinkEvent e) { |
149 |
closeMessage(); |
150 |
|
151 |
} |
152 |
|
153 |
}); |
154 |
|
155 |
new Label(informationComp, SWT.NONE); |
156 |
|
157 |
descriptionLabel = new Label(informationComp, SWT.WRAP); |
158 |
GridDataFactory.swtDefaults().span(2, 1).applyTo(descriptionLabel); |
159 |
constructed = true; |
160 |
return head; |
161 |
} |
162 |
|
163 |
private void closeMessage() { |
164 |
if (currentMessage != null) { |
165 |
setHidden(true); |
166 |
TasksUiPlugin.getDefault().getPreferenceStore().setValue( |
167 |
ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_ID, currentMessage.getId()); |
168 |
} |
169 |
} |
170 |
|
171 |
public void setHidden(boolean hidden) { |
172 |
headData.exclude = hidden; |
173 |
if (constructed) { |
174 |
parent.layout(true); |
175 |
} |
176 |
} |
177 |
|
178 |
// From EditorUtil |
179 |
private static Font setHeaderFontSizeAndStyle(Control text) { |
180 |
float sizeFactor = 1.2f; |
181 |
Font initialFont = text.getFont(); |
182 |
FontData[] fontData = initialFont.getFontData(); |
183 |
for (FontData element : fontData) { |
184 |
element.setHeight((int) (element.getHeight() * sizeFactor)); |
185 |
element.setStyle(element.getStyle() | SWT.BOLD); |
186 |
} |
187 |
final Font textFont = new Font(text.getDisplay(), fontData); |
188 |
text.setFont(textFont); |
189 |
text.addDisposeListener(new DisposeListener() { |
190 |
public void widgetDisposed(DisposeEvent e) { |
191 |
textFont.dispose(); |
192 |
} |
193 |
}); |
194 |
Color color = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get( |
195 |
CommonThemes.COLOR_COMPLETED); |
196 |
text.setForeground(color); |
197 |
return textFont; |
198 |
} |
199 |
|
200 |
public void setServiceMessage(final ServiceMessage message) { |
201 |
if (message != null) { |
202 |
String lastMessageId = TasksUiPlugin.getDefault().getPreferenceStore().getString( |
203 |
ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_ID); |
204 |
TasksUiPlugin.getDefault().getPreferenceStore().setValue( |
205 |
ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_ETAG, message.getETag()); |
206 |
TasksUiPlugin.getDefault().getPreferenceStore().setValue( |
207 |
ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_LAST_MODIFIED, message.getLastModified()); |
208 |
|
209 |
boolean displayForCurrentMylynVersion = true; |
210 |
|
211 |
if (message.getMylynVersion() != null && !message.getMylynVersion().equals("")) { //$NON-NLS-1$ |
212 |
|
213 |
MylynVersion version = new MylynVersion(message.getMylynVersion()); |
214 |
String versionString = (String) TasksUiPlugin.getDefault().getBundle().getHeaders().get( |
215 |
"Bundle-Version"); //$NON-NLS-1$ |
216 |
MylynVersion versionInstalled = new MylynVersion(versionString); |
217 |
|
218 |
displayForCurrentMylynVersion = (versionInstalled.compareTo(version) <= 0); |
219 |
} |
220 |
|
221 |
if (displayForCurrentMylynVersion && !lastMessageId.equals(message.getId()) |
222 |
&& !message.getId().equals("-1")) { //$NON-NLS-1$ |
223 |
currentMessage = message; |
224 |
Display.getDefault().asyncExec(new Runnable() { |
225 |
|
226 |
public void run() { |
227 |
if (!head.isDisposed()) { |
228 |
if (message != null) { |
229 |
setTitle(message.getTitle()); |
230 |
setDescription(message.getDescription()); |
231 |
setTitleImage(Dialog.getImage(message.getImage())); |
232 |
setHidden(false); |
233 |
setMessageUrl(message.getUrl()); |
234 |
} else { |
235 |
setHidden(true); |
236 |
} |
237 |
} |
238 |
|
239 |
} |
240 |
}); |
241 |
} |
242 |
} else { |
243 |
setHidden(true); |
244 |
} |
245 |
} |
246 |
|
247 |
} |