diff options
author | Matthias Sohn | 2017-05-30 10:57:00 +0000 |
---|---|---|
committer | Matthias Sohn | 2017-05-30 10:57:07 +0000 |
commit | 23a9a3eb8597ca6059f60f2d90521e4946294068 (patch) | |
tree | dc1512465077b37be7533eb82dac5844b822db32 | |
parent | 44f164e47eb7dba156b742618609c16ec4ed5bf4 (diff) | |
parent | afa702f00581346a4265932f85cfce29d2db14b5 (diff) | |
download | egit-github-23a9a3eb8597ca6059f60f2d90521e4946294068.tar.gz egit-github-23a9a3eb8597ca6059f60f2d90521e4946294068.tar.xz egit-github-23a9a3eb8597ca6059f60f2d90521e4946294068.zip |
Merge branch 'master' into stable-4.8
* master:
Resolve compilation problem on Oxygen
Change-Id: Icfdf7db561c37a31bad46ba7c0a1741db32c924e
5 files changed, 251 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.github.ui/icons/etool16/person-me.gif b/org.eclipse.mylyn.github.ui/icons/etool16/person-me.gif Binary files differnew file mode 100644 index 00000000..fa074fb8 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/icons/etool16/person-me.gif diff --git a/org.eclipse.mylyn.github.ui/icons/etool16/person.gif b/org.eclipse.mylyn.github.ui/icons/etool16/person.gif Binary files differnew file mode 100644 index 00000000..dc5a1af8 --- /dev/null +++ b/org.eclipse.mylyn.github.ui/icons/etool16/person.gif diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java index 1f67d483..906cc5d4 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/GitHubImages.java @@ -26,6 +26,8 @@ public class GitHubImages { private static final String ICONS_PATH = "icons/"; //$NON-NLS-1$ private static final String PATH_OBJ = ICONS_PATH + "obj16/"; //$NON-NLS-1$ + private static final String PATH_TOOL = ICONS_PATH + "etool16/"; //$NON-NLS-1$ + private static ImageRegistry manager; public static final String GITHUB_LOGO_OBJ = NAME_PREFIX + "OBJ_GITHUB_LOGO"; //$NON-NLS-1$ @@ -42,6 +44,9 @@ public class GitHubImages { public static final ImageDescriptor DESC_GITHUB_UNCHECKALL = create(PATH_OBJ, "uncheckall.gif"); //$NON-NLS-1$ public static final ImageDescriptor DESC_GITHUB_ORG = create(PATH_OBJ, "org.png"); //$NON-NLS-1$ + public static final ImageDescriptor DESC_PERSON = create(PATH_TOOL, "person.gif"); //$NON-NLS-1$ + public static final ImageDescriptor DESC_PERSON_ME = create(PATH_TOOL, "person-me.gif"); //$NON-NLS-1$ + private static ImageDescriptor create(String prefix, String name) { return ImageDescriptor.createFromURL(makeImageURL(prefix, name)); } diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java index dd67b5a0..0e781bc9 100644 --- a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentPart.java @@ -198,7 +198,7 @@ public class GistAttachmentPart extends AbstractTaskEditorPart { attachmentList.add(taskAttachment); } attachmentsViewer.setContentProvider(new ArrayContentProvider()); - attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider( + attachmentsViewer.setLabelProvider(new GistAttachmentTableLabelProvider( getModel(), getTaskEditorPage().getAttributeEditorToolkit()) { public String getColumnText(Object element, int columnIndex) { diff --git a/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentTableLabelProvider.java b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentTableLabelProvider.java new file mode 100644 index 00000000..fb649aed --- /dev/null +++ b/org.eclipse.mylyn.github.ui/src/org/eclipse/mylyn/internal/github/ui/gist/GistAttachmentTableLabelProvider.java @@ -0,0 +1,245 @@ +/******************************************************************************* + * Copyright (c) 2004, 2011 Tasktop Technologies 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: + * Tasktop Technologies - initial API and implementation + * Frank Becker - indicate deprecated attachments, bug 215549 + * Perforce - fixes for bug 318505 + *******************************************************************************/ +package org.eclipse.mylyn.internal.github.ui.gist; + +import java.text.DateFormat; + +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.jface.resource.LocalResourceManager; +import org.eclipse.jface.resource.ResourceManager; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ViewerCell; +// The following three packages were relocated from org.eclipse.mylyn.internal.provisional.commons.ui... +//import org.eclipse.mylyn.commons.ui.CommonImages; +//import org.eclipse.mylyn.commons.ui.compatibility.CommonThemes; +//import org.eclipse.mylyn.commons.workbench.CommonImageManger; +import org.eclipse.mylyn.internal.github.ui.GitHubImages; +import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentSizeFormatter; +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.TaskDataModel; +import org.eclipse.mylyn.tasks.ui.TasksUiImages; +import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorToolkit; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.ui.PlatformUI; + +/** + * Copied from org.eclipse.mylyn.tasks.ui, + * org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentTableLabelProvider, + * commit SHA 70d3be89608a56a87862c30f4f1f2cd98d04a521, and then adapted to + * compile against Mylyn 3.7 (base version of egit-github) and 3.23 (current + * version as of 2017). + * + * Used in GistAttachmentPart, which previously used the Mylyn-internal + * AttachmentTableLabelProvider directly. Unfortunately, that class changed + * in non-compatible ways with Mylyn Tasks 3.23.0. + */ +public class GistAttachmentTableLabelProvider extends ColumnLabelProvider { + + private final AttachmentSizeFormatter sizeFormatter = AttachmentSizeFormatter.getInstance(); + + private final TaskDataModel model; + + private final AttributeEditorToolkit attributeEditorToolkit; + + private final ResourceManager imageManager; + + public GistAttachmentTableLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit) { + this.model = model; + this.attributeEditorToolkit = attributeEditorToolkit; + this.imageManager = new LocalResourceManager(JFaceResources.getResources()); + } + + public Image getColumnImage(Object element, int columnIndex) { + ITaskAttachment attachment = (ITaskAttachment) element; + if (columnIndex == 0) { + if (AttachmentUtil.isContext(attachment)) { + return (Image) imageManager.get(TasksUiImages.CONTEXT_TRANSFER); + } else if (attachment.isPatch()) { + return (Image) imageManager.get(TasksUiImages.TASK_ATTACHMENT_PATCH); + } else { + return getFileImage(attachment.getFileName()); + } + } else if (columnIndex == 3 && attachment.getAuthor() != null) { + return getAuthorImage(attachment.getAuthor(), attachment.getTaskRepository()); + } + return null; + } + + /** + * Simplified implementation of {@link org.eclipse.mylyn.commons.workbench.CommonImageManager#getFileName(String)}. + * The CommonImageManagerPackage was relocated from package org.eclipse.mylyn.internal.provisional.commons.ui + * some time after Mylyn 3.7. + * + * @param filename to get an image for + * @return the image + */ + private Image getFileImage(String filename) { + return (Image) imageManager.get(PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor(filename)); + } + + /** + * Get author image for a specified repository person and task repository + * + * @param person + * @param repository + * @return author image + */ + protected Image getAuthorImage(IRepositoryPerson person, TaskRepository repository) { + // These two images have been copied from org.eclipse.mylyn.commons.ui; 3.23.0 + if (repository != null && person != null && person.getPersonId().equals(repository.getUserName())) { + return (Image) imageManager.get(GitHubImages.DESC_PERSON_ME); + } else { + return (Image) imageManager.get(GitHubImages.DESC_PERSON); + } + } + + public String getColumnText(Object element, int columnIndex) { + ITaskAttachment attachment = (ITaskAttachment) element; + switch (columnIndex) { + case 0: + if (AttachmentUtil.isContext(attachment)) { + return org.eclipse.mylyn.internal.tasks.ui.editors.Messages.AttachmentTableLabelProvider_Task_Context; + } else if (attachment.isPatch()) { + return org.eclipse.mylyn.internal.tasks.ui.editors.Messages.AttachmentTableLabelProvider_Patch; + } else { + return " " + attachment.getFileName(); //$NON-NLS-1$ + } + case 1: + return attachment.getDescription(); + case 2: + Long length = attachment.getLength(); + if (length < 0) { + return "-"; //$NON-NLS-1$ + } + return sizeFormatter.format(length); + case 3: + return (attachment.getAuthor() != null) ? attachment.getAuthor().toString() : ""; //$NON-NLS-1$ + case 4: + return (attachment.getCreationDate() != null) +// ? EditorUtil.formatDateTime(attachment.getCreationDate()) + ? DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.SHORT).format(attachment.getCreationDate()) + : ""; //$NON-NLS-1$ + case 5: + // FIXME add id to ITaskAttachment + return getAttachmentId(attachment); + } + return "unrecognized column"; //$NON-NLS-1$ + } + + static String getAttachmentId(ITaskAttachment attachment) { + String a = attachment.getUrl(); + if (a != null) { + int i = a.indexOf("?id="); //$NON-NLS-1$ + if (i != -1) { + return a.substring(i + 4); + } + } + return ""; //$NON-NLS-1$ + } + + @Override + public void addListener(ILabelProviderListener listener) { + // ignore + } + + @Override + public void dispose() { + imageManager.dispose(); + } + + @Override + public boolean isLabelProperty(Object element, String property) { + // ignore + return false; + } + + @Override + public void removeListener(ILabelProviderListener listener) { + // ignore + } + +// @Override +// public Color getForeground(Object element) { +// ITaskAttachment att = (ITaskAttachment) element; +// if (att.isDeprecated()) { +// IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager(); +// return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_COMPLETED); +// } +// return super.getForeground(element); +// } + + @Override + public String getToolTipText(Object element) { + ITaskAttachment attachment = (ITaskAttachment) element; + StringBuilder sb = new StringBuilder(); + sb.append(org.eclipse.mylyn.internal.tasks.ui.editors.Messages.AttachmentTableLabelProvider_File_); + sb.append(attachment.getFileName()); + if (attachment.getContentType() != null) { + sb.append("\n"); //$NON-NLS-1$ + sb.append(org.eclipse.mylyn.internal.tasks.ui.editors.Messages.AttachmentTableLabelProvider_Type_); + sb.append(attachment.getContentType()); + } + return sb.toString(); + /*"\nFilename\t\t" + attachment.getAttributeValue("filename") + +"ID\t\t\t" + attachment.getAttributeValue("attachid") + + "\nDate\t\t\t" + attachment.getAttributeValue("date") + + "\nDescription\t" + attachment.getAttributeValue("desc") + + "\nCreator\t\t" + attachment.getCreator() + + "\nType\t\t\t" + attachment.getAttributeValue("type") + + "\nURL\t\t\t" + attachment.getAttributeValue("task.common.attachment.url");*/ + } + + @Override + public Point getToolTipShift(Object object) { + return new Point(5, 5); + } + + @Override + public int getToolTipDisplayDelayTime(Object object) { + return 200; + } + + @Override + public int getToolTipTimeDisplayed(Object object) { + return 5000; + } + + @Override + public void update(ViewerCell cell) { + Object element = cell.getElement(); + cell.setText(getColumnText(element, cell.getColumnIndex())); + Image image = getColumnImage(element, cell.getColumnIndex()); + cell.setImage(image); + cell.setBackground(getBackground(element)); + cell.setForeground(getForeground(element)); + cell.setFont(getFont(element)); + } + + @Override + public Color getBackground(Object element) { + if (model != null && attributeEditorToolkit != null) { + ITaskAttachment attachment = (ITaskAttachment) element; + if (model.hasIncomingChanges(attachment.getTaskAttribute())) { + return attributeEditorToolkit.getColorIncoming(); + } + } + return null; + } + +}
\ No newline at end of file |