Skip to main content
summaryrefslogtreecommitdiffstats
blob: eef93ca82d8faa3d222b4133564b40c2b457873b (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
/*******************************************************************************
 * Copyright (c) 2010, 2015 Frank Becker 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:
 *     Frank Becker - initial API and implementation
 *******************************************************************************/

package org.eclipse.mylyn.internal.tasks.ui.editors;

import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.mylyn.commons.ui.CommonImages;
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tasks.ui.TasksUiImages;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.WorkbenchImages;

/**
 * @author Frank Becker
 */
public class TaskEditorOutlineNodeLabelProvider extends LabelProvider {

	private static final String[] IMAGE_EXTENSIONS = { "jpg", "gif", "png", "tiff", "tif", "bmp" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$	@Override

	@Override
	public Image getImage(Object element) {
		if (element instanceof TaskEditorOutlineNode) {
			TaskEditorOutlineNode node = (TaskEditorOutlineNode) element;
			if (TaskEditorOutlineNode.LABEL_COMMENTS.equals(node.getLabel())
					|| TaskEditorOutlineNode.LABEL_NEW_COMMENT.equals(node.getLabel())) {
				return CommonImages.getImage(TasksUiImages.COMMENT);
			}
			if (TaskEditorOutlineNode.LABEL_DESCRIPTION.equals(node.getLabel())) {
				return CommonImages.getImage(TasksUiImages.TASK_NOTES);
			} else if (node.getTaskComment() != null) {
				IRepositoryPerson author = node.getTaskComment().getAuthor();
				TaskAttribute taskAttribute = node.getData();
				String repositoryUrl = taskAttribute.getTaskData().getRepositoryUrl();
				String connectorKind = null;
				TaskRepository taskRepository = null;
				if (repositoryUrl != null) {
					connectorKind = taskAttribute.getTaskData().getConnectorKind();
					if (connectorKind != null) {
						taskRepository = TasksUi.getRepositoryManager().getRepository(connectorKind, repositoryUrl);
					}
				}
				if (taskRepository != null && author != null && author.matchesUsername(taskRepository.getUserName())) {
					return CommonImages.getImage(CommonImages.PERSON_ME);
				} else {
					return CommonImages.getImage(CommonImages.PERSON);
				}
			} else if (node.getTaskAttachment() != null) {
				ITaskAttachment attachment = node.getTaskAttachment();
				if (AttachmentUtil.isContext(attachment)) {
					return CommonImages.getImage(TasksUiImages.CONTEXT_TRANSFER);
				} else if (attachment.isPatch()) {
					return CommonImages.getImage(TasksUiImages.TASK_ATTACHMENT_PATCH);
				} else {
					String filename = attachment.getFileName();
					if (filename != null) {
						int dotIndex = filename.lastIndexOf('.');
						if (dotIndex != -1) {
							String fileType = filename.substring(dotIndex + 1);
							for (String element2 : IMAGE_EXTENSIONS) {
								if (element2.equalsIgnoreCase(fileType)) {
									return CommonImages.getImage(CommonImages.IMAGE_FILE);
								}
							}
						}
					}
					return WorkbenchImages.getImage(ISharedImages.IMG_OBJ_FILE);
				}
			} else if (node.getParent() == null) {
				return CommonImages.getImage(TasksUiImages.TASK);
			} else if (TaskEditorOutlineNode.LABEL_RELATED_TASKS.equals(node.getLabel())
					|| TaskEditorOutlineNode.LABEL_ATTRIBUTES.equals(node.getLabel())) {
				return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER);
			}
			return CommonImages.getImage(TasksUiImages.TASK);
		}
		return null;
	}

	@Override
	public String getText(Object element) {
		if (element instanceof TaskEditorOutlineNode) {
			TaskEditorOutlineNode node = (TaskEditorOutlineNode) element;
			if (TaskEditorOutlineNode.LABEL_COMMENTS.equals(node.getLabel())
					|| TaskEditorOutlineNode.LABEL_NEW_COMMENT.equals(node.getLabel())
					|| TaskEditorOutlineNode.LABEL_DESCRIPTION.equals(node.getLabel())) {
				return node.getLabel();
			}
			if (node.getData() != null && node.getTaskAttachment() == null && node.getTaskComment() == null) {
				// regular attribute
				TaskAttribute taskAttribute = node.getData();
				String label = taskAttribute.getTaskData().getAttributeMapper().getLabel(taskAttribute);
				if (!label.endsWith(":")) { //$NON-NLS-1$
					label += ":"; //$NON-NLS-1$
				}
				return label + " " + taskAttribute.getTaskData().getAttributeMapper().getValueLabel(taskAttribute); //$NON-NLS-1$
			}
			return node.getLabel();
		}
		return super.getText(element);
	}

}

Back to the top