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.swt.SWT; |
24 |
import org.eclipse.swt.events.DisposeEvent; |
25 |
import org.eclipse.swt.events.DisposeListener; |
26 |
import org.eclipse.swt.graphics.Color; |
27 |
import org.eclipse.swt.graphics.Font; |
28 |
import org.eclipse.swt.graphics.FontData; |
29 |
import org.eclipse.swt.graphics.Image; |
30 |
import org.eclipse.swt.layout.GridData; |
31 |
import org.eclipse.swt.layout.GridLayout; |
32 |
import org.eclipse.swt.widgets.Composite; |
33 |
import org.eclipse.swt.widgets.Control; |
34 |
import org.eclipse.swt.widgets.Display; |
35 |
import org.eclipse.swt.widgets.Label; |
36 |
import org.eclipse.ui.PlatformUI; |
37 |
import org.eclipse.ui.forms.FormColors; |
38 |
import org.eclipse.ui.forms.IFormColors; |
39 |
import org.eclipse.ui.forms.events.HyperlinkAdapter; |
40 |
import org.eclipse.ui.forms.events.HyperlinkEvent; |
41 |
import org.eclipse.ui.forms.events.IHyperlinkListener; |
42 |
import org.eclipse.ui.forms.widgets.Hyperlink; |
43 |
import org.eclipse.ui.forms.widgets.ImageHyperlink; |
44 |
|
45 |
/** |
46 |
* @author Robert Elves |
47 |
*/ |
48 |
public class TaskListServiceMessageControl implements IServiceMessageListener { |
49 |
|
50 |
private ImageHyperlink imageHyperlink; |
51 |
|
52 |
private Hyperlink titleHyperlink; |
53 |
|
54 |
private Label descriptionLabel; |
55 |
|
56 |
private GridData headData; |
57 |
|
58 |
private final Composite parent; |
59 |
|
60 |
private GradientCanvas head; |
61 |
|
62 |
private ImageHyperlink closeLink; |
63 |
|
64 |
private ServiceMessage currentMessage; |
65 |
|
66 |
private boolean constructed; |
67 |
|
68 |
public TaskListServiceMessageControl(Composite parent) { |
69 |
this.parent = parent; |
70 |
createControl(parent); |
71 |
} |
72 |
|
73 |
private void setTitleImage(Image image) { |
74 |
imageHyperlink.setImage(image); |
75 |
} |
76 |
|
77 |
private void setTitle(String title) { |
78 |
titleHyperlink.setText(title); |
79 |
} |
80 |
|
81 |
private void setDescription(String description) { |
82 |
descriptionLabel.setText(description); |
83 |
} |
84 |
|
85 |
private void addHyperlinkListener(IHyperlinkListener listener) { |
86 |
titleHyperlink.addHyperlinkListener(listener); |
87 |
imageHyperlink.addHyperlinkListener(listener); |
88 |
} |
89 |
|
90 |
public Control createControl(Composite parent) { |
91 |
FormColors colors = new FormColors(parent.getDisplay()); |
92 |
head = new GradientCanvas(parent, SWT.NONE); |
93 |
GridLayout headLayout = new GridLayout(); |
94 |
headLayout.marginHeight = 0; |
95 |
headLayout.marginWidth = 0; |
96 |
headLayout.horizontalSpacing = 0; |
97 |
headLayout.verticalSpacing = 0; |
98 |
headLayout.numColumns = 1; |
99 |
head.setLayout(headLayout); |
100 |
headData = new GridData(SWT.FILL, SWT.TOP, true, false); |
101 |
head.setLayoutData(headData); |
102 |
setHidden(true); |
103 |
|
104 |
Color top = colors.getColor(IFormColors.H_GRADIENT_END); |
105 |
Color bot = colors.getColor(IFormColors.H_GRADIENT_START); |
106 |
head.setBackgroundGradient(new Color[] { bot, top }, new int[] { 100 }, true); |
107 |
head.setSeparatorVisible(true); |
108 |
head.setSeparatorAlignment(SWT.TOP); |
109 |
|
110 |
head.putColor(IFormColors.H_BOTTOM_KEYLINE1, colors.getColor(IFormColors.H_BOTTOM_KEYLINE1)); |
111 |
head.putColor(IFormColors.H_BOTTOM_KEYLINE2, colors.getColor(IFormColors.H_BOTTOM_KEYLINE2)); |
112 |
head.putColor(IFormColors.H_HOVER_LIGHT, colors.getColor(IFormColors.H_HOVER_LIGHT)); |
113 |
head.putColor(IFormColors.H_HOVER_FULL, colors.getColor(IFormColors.H_HOVER_FULL)); |
114 |
head.putColor(IFormColors.TB_TOGGLE, colors.getColor(IFormColors.TB_TOGGLE)); |
115 |
head.putColor(IFormColors.TB_TOGGLE_HOVER, colors.getColor(IFormColors.TB_TOGGLE_HOVER)); |
116 |
|
117 |
Composite informationComp = new Composite(head, SWT.NONE); |
118 |
informationComp.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false));//new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL)); |
119 |
informationComp.setLayout(new GridLayout(3, false)); |
120 |
|
121 |
imageHyperlink = new ImageHyperlink(informationComp, SWT.NONE); |
122 |
|
123 |
titleHyperlink = new Hyperlink(informationComp, SWT.WRAP); |
124 |
setHeaderFontSizeAndStyle(titleHyperlink); |
125 |
|
126 |
closeLink = new ImageHyperlink(informationComp, SWT.NONE); |
127 |
closeLink.setImage(CommonImages.getImage(CommonImages.NOTIFICATION_CLOSE)); |
128 |
GridDataFactory.fillDefaults().align(SWT.END, SWT.BEGINNING).applyTo(closeLink); |
129 |
closeLink.addHyperlinkListener(new HyperlinkAdapter() { |
130 |
@Override |
131 |
public void linkActivated(HyperlinkEvent e) { |
132 |
closeMessage(); |
133 |
|
134 |
} |
135 |
|
136 |
}); |
137 |
|
138 |
new Label(informationComp, SWT.NONE); |
139 |
|
140 |
descriptionLabel = new Label(informationComp, SWT.WRAP); |
141 |
GridDataFactory.swtDefaults().span(2, 1).applyTo(descriptionLabel); |
142 |
constructed = true; |
143 |
return head; |
144 |
} |
145 |
|
146 |
private void closeMessage() { |
147 |
if (currentMessage != null) { |
148 |
setHidden(true); |
149 |
TasksUiPlugin.getDefault().getPreferenceStore().setValue( |
150 |
ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_ID, currentMessage.getId()); |
151 |
} |
152 |
} |
153 |
|
154 |
public void setHidden(boolean hidden) { |
155 |
headData.exclude = hidden; |
156 |
if (constructed) { |
157 |
parent.layout(true); |
158 |
} |
159 |
} |
160 |
|
161 |
// From EditorUtil |
162 |
private static Font setHeaderFontSizeAndStyle(Control text) { |
163 |
float sizeFactor = 1.2f; |
164 |
Font initialFont = text.getFont(); |
165 |
FontData[] fontData = initialFont.getFontData(); |
166 |
for (FontData element : fontData) { |
167 |
element.setHeight((int) (element.getHeight() * sizeFactor)); |
168 |
element.setStyle(element.getStyle() | SWT.BOLD); |
169 |
} |
170 |
final Font textFont = new Font(text.getDisplay(), fontData); |
171 |
text.setFont(textFont); |
172 |
text.addDisposeListener(new DisposeListener() { |
173 |
public void widgetDisposed(DisposeEvent e) { |
174 |
textFont.dispose(); |
175 |
} |
176 |
}); |
177 |
Color color = PlatformUI.getWorkbench().getThemeManager().getCurrentTheme().getColorRegistry().get( |
178 |
CommonThemes.COLOR_COMPLETED); |
179 |
text.setForeground(color); |
180 |
return textFont; |
181 |
} |
182 |
|
183 |
public void setServiceMessage(final ServiceMessage message) { |
184 |
if (message != null) { |
185 |
String lastMessageId = TasksUiPlugin.getDefault().getPreferenceStore().getString( |
186 |
ITasksUiPreferenceConstants.LAST_SERVICE_MESSAGE_ID); |
187 |
if (!lastMessageId.equals(message.getId())) { |
188 |
currentMessage = message; |
189 |
Display.getDefault().asyncExec(new Runnable() { |
190 |
|
191 |
public void run() { |
192 |
if (message != null) { |
193 |
setTitle(message.getTitle()); |
194 |
setDescription(message.getDescription()); |
195 |
setTitleImage(Dialog.getImage(message.getImage())); |
196 |
setHidden(false); |
197 |
} else { |
198 |
setHidden(true); |
199 |
} |
200 |
|
201 |
} |
202 |
}); |
203 |
} |
204 |
} |
205 |
} |
206 |
|
207 |
} |