Skip to main content
summaryrefslogtreecommitdiffstats
blob: 6eac12faac12a32a0378bca6a8d4fc2bece9c379 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.help.ui.dialogs;

import java.util.Collection;
import java.util.List;

import org.eclipse.jface.dialogs.PopupDialog;
import org.eclipse.mylyn.internal.tasks.ui.TaskListColorsAndFonts;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiImages;
import org.eclipse.mylyn.internal.tasks.ui.views.TaskElementLabelProvider;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.AbstractTaskContainer;
import org.eclipse.mylyn.tasks.core.AbstractTask.PriorityLevel;
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.forms.events.HyperlinkAdapter;
import org.eclipse.ui.forms.events.HyperlinkEvent;
import org.eclipse.ui.forms.events.IHyperlinkListener;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.Hyperlink;
import org.eclipse.ui.forms.widgets.ImageHyperlink;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.internal.themes.ColorsAndFontsPreferencePage;
import org.eclipse.ui.themes.IThemeManager;

/**
 * @author Mik Kersten
 */
public class UiLegendDialog extends PopupDialog {

	public static final String TITLE = "Mylyn UI Legend";

	private FormToolkit toolkit;

	private ScrolledForm form;

	private TaskElementLabelProvider labelProvider = new TaskElementLabelProvider(false);

	private IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();

	public UiLegendDialog(Shell parent) {
		super(parent, PopupDialog.INFOPOPUP_SHELLSTYLE | SWT.ON_TOP, false, false, false, false, null, null);
	}

	@Override
	protected Control createContents(Composite parent) {
		getShell().setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_GRAY));

		return createDialogArea(parent);
	}

	@Override
	public int open() {
		int open = super.open();
		getShell().setFocus();
		return open;
	}

	@Override
	public boolean close() {
		if (toolkit != null) {
			if (toolkit.getColors() != null) {
				toolkit.dispose();
			}
		}
		return super.close();
	}

	@Override
	protected final Control createDialogArea(final Composite parent) {

		getShell().setText(TITLE);

		toolkit = new FormToolkit(parent.getDisplay());
		form = toolkit.createScrolledForm(parent);
		GridLayout formLayout = new GridLayout();
		formLayout.numColumns = 1;
		form.getBody().setLayout(formLayout);
		Label image = null;

		Section section = toolkit.createSection(form.getBody(), Section.DESCRIPTION);
		section.setText(TITLE + "                                                        ");
		Composite sectionClient = toolkit.createComposite(section);
		GridLayout layout = new GridLayout();
		layout.verticalSpacing = 0;
		layout.horizontalSpacing = 0;
		layout.verticalSpacing = 0;
		layout.marginHeight = 0;
		layout.marginTop = 0;
		sectionClient.setLayout(layout);

		Composite buttonsComposite = toolkit.createComposite(section);
		GridLayout buttonsLayout = new GridLayout();
		buttonsLayout.verticalSpacing = 0;
		buttonsLayout.verticalSpacing = 0;
		buttonsLayout.marginHeight = 0;
		buttonsLayout.marginWidth = 0;
		buttonsComposite.setLayout(buttonsLayout);
		section.setTextClient(buttonsComposite);
		final ImageHyperlink closeHyperlink = toolkit.createImageHyperlink(buttonsComposite, SWT.NONE);
		closeHyperlink.setLayout(buttonsLayout);
		closeHyperlink.setImage(TasksUiImages.getImage(TasksUiImages.NOTIFICATION_CLOSE));
		closeHyperlink.addHyperlinkListener(new HyperlinkAdapter() {
			@Override
			public void linkActivated(HyperlinkEvent e) {
				close();
			}
		});

		// TODO: get rid of ridiculous space-based padding

		Composite tasksComposite = toolkit.createComposite(form.getBody());
		tasksComposite.setLayout(new GridLayout(2, false));

		section = toolkit.createSection(tasksComposite, Section.TITLE_BAR);
		section.setText("Tasks");
		sectionClient = toolkit.createComposite(section);
		setSectionLayout(sectionClient, section, false);

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK));
		toolkit.createLabel(sectionClient, "Task                       ");

// image = toolkit.createLabel(sectionClient, "");
// image.setImage(TasksUiImages.getImage(TasksUiImages.TASK_NOTES));
// toolkit.createLabel(sectionClient, "Task with notes");

// image = toolkit.createLabel(sectionClient, "");
// image.setImage(TasksUiImages.getImage(TasksUiImages.TASK_REPOSITORY));
// toolkit.createLabel(sectionClient, "Repository task");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.CATEGORY));
		toolkit.createLabel(sectionClient, "Category");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.QUERY));
		toolkit.createLabel(sectionClient, "Query");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.CALENDAR));
		toolkit.createLabel(sectionClient, "Date range");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.BLANK));

		section = toolkit.createSection(tasksComposite, Section.TITLE_BAR);
		section.setText("Priorities                       ");
		sectionClient = toolkit.createComposite(section);
		setSectionLayout(sectionClient, section, false);

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.PRIORITY_1));
		toolkit.createLabel(sectionClient, PriorityLevel.P1.getDescription());

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.PRIORITY_2));
		toolkit.createLabel(sectionClient, PriorityLevel.P2.getDescription());

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.PRIORITY_3));
		toolkit.createLabel(sectionClient, PriorityLevel.P3.getDescription() + " (default)");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.PRIORITY_4));
		toolkit.createLabel(sectionClient, PriorityLevel.P4.getDescription());

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.PRIORITY_5));
		toolkit.createLabel(sectionClient, PriorityLevel.P5.getDescription());

		section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
		section.setText("Task Activity                                                                   ");
		sectionClient = toolkit.createComposite(section);
		setSectionLayout(sectionClient, section, false);

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK));
		Label labelOverdue = toolkit.createLabel(sectionClient, "Past scheduled date");
		labelOverdue.setForeground(themeManager.getCurrentTheme().getColorRegistry().get(
				TaskListColorsAndFonts.THEME_COLOR_TASK_OVERDUE));

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK));
		Label labelToday = toolkit.createLabel(sectionClient, "Scheduled for today");
		labelToday.setForeground(themeManager.getCurrentTheme().getColorRegistry().get(
				TaskListColorsAndFonts.THEME_COLOR_TASK_TODAY_SCHEDULED));

// image = toolkit.createLabel(sectionClient, "");
// image.setImage(TasksUiImages.getImage(TasksUiImages.TASK));
// Label labelThisWeek = toolkit.createLabel(sectionClient, "Scheduled for this
// week");
// labelThisWeek.setForeground(themeManager.getCurrentTheme().getColorRegistry().get(
// TaskListColorsAndFonts.THEME_COLOR_TASK_THISWEEK_SCHEDULED));

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK));
		Label labelCompleted = toolkit.createLabel(sectionClient, "Completed");
		labelCompleted.setFont(TaskListColorsAndFonts.STRIKETHROUGH);
// labelCompleted.setForeground(TaskListColorsAndFonts.COLOR_TASK_COMPLETED);
		labelCompleted.setForeground(themeManager.getCurrentTheme().getColorRegistry().get(
				TaskListColorsAndFonts.THEME_COLOR_COMPLETED));

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK));
		Label labelCompletedToday = toolkit.createLabel(sectionClient, "Completed today");
		labelCompletedToday.setFont(TaskListColorsAndFonts.STRIKETHROUGH);
		labelCompletedToday.setForeground(themeManager.getCurrentTheme().getColorRegistry().get(
				TaskListColorsAndFonts.THEME_COLOR_TASK_TODAY_COMPLETED));

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_HAS_DUE));
		toolkit.createLabel(sectionClient, "Due date set");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_OVER_DUE));
		toolkit.createLabel(sectionClient, "Due date past");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.BLANK));
		Hyperlink adjust = toolkit.createHyperlink(sectionClient, "Adjust Colors and Fonts...", SWT.NULL);
		adjust.addHyperlinkListener(new IHyperlinkListener() {

			public void linkActivated(HyperlinkEvent e) {
				ColorsAndFontsPreferencePage page = new ColorsAndFontsPreferencePage();
				page.init(PlatformUI.getWorkbench());
				TasksUiUtil.showPreferencePage(TasksUiUtil.PREFS_PAGE_ID_COLORS_AND_FONTS, page);
			}

			public void linkEntered(HyperlinkEvent e) {
				// ignore
			}

			public void linkExited(HyperlinkEvent e) {
				// ignore
			}
		});

		section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
		section.setText("Context                                                                            ");
		sectionClient = toolkit.createComposite(section);
		setSectionLayout(sectionClient, section, false);

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK_INACTIVE));
		toolkit.createLabel(sectionClient, "Inactive task with no context");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK_INACTIVE_CONTEXT));
		toolkit.createLabel(sectionClient, "Inactive task with context");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.TASK_ACTIVE));
		toolkit.createLabel(sectionClient, "Active task");

		section = toolkit.createSection(form.getBody(), Section.TITLE_BAR);
		section.setText("Synchronization                                                             ");
		sectionClient = toolkit.createComposite(section);
		setSectionLayout(sectionClient, section, true);

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_INCOMMING_NEW));
		toolkit.createLabel(sectionClient, "New task, open to view");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_INCOMMING));
		toolkit.createLabel(sectionClient, "Incoming changes, open to view");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_OUTGOING));
		toolkit.createLabel(sectionClient, "Outgoing changes");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_WARNING));
		toolkit.createLabel(sectionClient, "Synchronization failed, mouse over for details");

		image = toolkit.createLabel(sectionClient, "");
		image.setImage(TasksUiImages.getImage(TasksUiImages.OVERLAY_CONFLICT));
		toolkit.createLabel(sectionClient, "Conflicting changes, need to synchronize");

		// Connector specifics
		Composite connectorComposite = toolkit.createComposite(form.getBody());
		connectorComposite.setLayout(new GridLayout(2, false));

		Collection<AbstractRepositoryConnector> connectors = TasksUiPlugin.getRepositoryManager()
				.getRepositoryConnectors();
		for (AbstractRepositoryConnector connector : connectors) {
			AbstractRepositoryConnectorUi connectorUi = TasksUiPlugin.getRepositoryUi(connector.getConnectorKind());
			if (connectorUi != null) {
				List<AbstractTaskContainer> elements = connectorUi.getLegendItems();

				if (!elements.isEmpty()) {
					section = toolkit.createSection(connectorComposite, Section.TITLE_BAR);
					String label = connector.getLabel();
					int parenIndex = label.indexOf('(');
					if (parenIndex != -1) {
						label = label.substring(0, parenIndex);
					}

					section.setText("Connector: " + label + " ");
					sectionClient = toolkit.createComposite(section);
					setSectionLayout(sectionClient, section, true);

					for (AbstractTaskContainer taskListElement : elements) {
						image = toolkit.createLabel(sectionClient, "");
						image.setImage(labelProvider.getImage(taskListElement));
						toolkit.createLabel(sectionClient, taskListElement.getSummary());
					}
				}
			}
		}

		form.pack();
		return parent;
	}

	private GridLayout setSectionLayout(Composite sectionClient, Section section, boolean extraPadding) {
		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.makeColumnsEqualWidth = false;
		layout.verticalSpacing = 0;
		if (extraPadding) {
			layout.verticalSpacing = 5;
			layout.horizontalSpacing = 8;
		} else {
			layout.horizontalSpacing = 5;
			layout.verticalSpacing = 1;
		}
		layout.marginHeight = 0;
		layout.marginTop = 0;
		sectionClient.setLayout(layout);
		section.setClient(sectionClient);

		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.grabExcessHorizontalSpace = true;
		gridData.verticalSpan = 2;
		sectionClient.setLayoutData(gridData);

		return layout;
	}
}

Back to the top