Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2011-09-01 18:07:26 +0000
committerFrank Becker2011-09-01 18:07:26 +0000
commit218ff6409520a1e0f1101e7b2e0511fac4b4214e (patch)
tree4b442a9f896c135e13962dad90f5fe92415c6ecb
parent655b1a2ddfbec8862f644336f942373ee658fed8 (diff)
downloadorg.eclipse.mylyn.tasks-218ff6409520a1e0f1101e7b2e0511fac4b4214e.tar.gz
org.eclipse.mylyn.tasks-218ff6409520a1e0f1101e7b2e0511fac4b4214e.tar.xz
org.eclipse.mylyn.tasks-218ff6409520a1e0f1101e7b2e0511fac4b4214e.zip
ASSIGNED - bug 305169: Use different color for attachments marked with
iplog flag https://bugs.eclipse.org/bugs/show_bug.cgi?id=305169
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/AttachmentColumnFlags.java64
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorAttachmentPart.java30
-rw-r--r--org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java17
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/AttachmentTableLabelProviderTest.java12
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreated.java37
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreator.java67
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDefinition.java87
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDescription.java36
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnID.java50
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnName.java59
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnSize.java43
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java88
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java55
13 files changed, 524 insertions, 121 deletions
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/AttachmentColumnFlags.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/AttachmentColumnFlags.java
new file mode 100644
index 000000000..1635a0c1a
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/AttachmentColumnFlags.java
@@ -0,0 +1,64 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.bugzilla.ui.editor;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnDefinition;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.swt.SWT;
+
+public class AttachmentColumnFlags extends AttachmentColumnDefinition {
+ public AttachmentColumnFlags(int index) {
+ super(index, 100, "Flag", SWT.LEFT, false, SWT.NONE);
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return getAttachmentFlags(attachment);
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ String key1 = getAttachmentFlags(attachment1);
+ String key2 = getAttachmentFlags(attachment2);
+ return compare(key1, key2);
+ }
+
+ static String getAttachmentFlags(ITaskAttachment attachment) {
+ TaskAttribute attribute = attachment.getTaskAttribute();
+ String result = ""; //$NON-NLS-1$
+ for (TaskAttribute attachmentAttribute : attribute.getAttributes().values()) {
+ String atribID = attachmentAttribute.getId();
+ if (!atribID.startsWith(BugzillaAttribute.KIND_FLAG)) {
+ continue;
+ }
+ TaskAttribute state = attachmentAttribute.getAttribute("state"); //$NON-NLS-1$
+ if (state != null) {
+ if (" ".equals(state.getValue())) { //$NON-NLS-1$
+ continue;
+ }
+ if (!"".equals(result)) { //$NON-NLS-1$
+ result += ", "; //$NON-NLS-1$
+ }
+ result += state.getMetaData().getLabel() + state.getValue();
+ }
+ }
+
+ return result;
+ }
+
+}
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorAttachmentPart.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorAttachmentPart.java
new file mode 100644
index 000000000..82f251b34
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorAttachmentPart.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.bugzilla.ui.editor;
+
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnCreated;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnCreator;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnDefinition;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnDescription;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnID;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnName;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnSize;
+import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorAttachmentPart;
+
+public class BugzillaTaskEditorAttachmentPart extends TaskEditorAttachmentPart {
+ @Override
+ public AttachmentColumnDefinition[] getColumnDefinitions() {
+ return new AttachmentColumnDefinition[] { new AttachmentColumnName(0), new AttachmentColumnDescription(1),
+ new AttachmentColumnSize(2), new AttachmentColumnCreator(3), new AttachmentColumnCreated(4),
+ new AttachmentColumnID(5), new AttachmentColumnFlags(6) };
+ }
+}
diff --git a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java
index 5ac2e55e2..4e3d8e008 100644
--- a/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java
+++ b/org.eclipse.mylyn.bugzilla.ui/src/org/eclipse/mylyn/internal/bugzilla/ui/editor/BugzillaTaskEditorPage.java
@@ -99,6 +99,7 @@ public class BugzillaTaskEditorPage extends AbstractTaskEditorPage {
Set<TaskEditorPartDescriptor> descriptors = super.createPartDescriptors();
boolean hasPartComments = false;
boolean hasPartNewComment = false;
+ boolean hasPartAttachments = false;
// remove unnecessary default editor parts
for (TaskEditorPartDescriptor taskEditorPartDescriptor : descriptors) {
if (taskEditorPartDescriptor.getId().equals(ID_PART_PEOPLE)) {
@@ -120,6 +121,13 @@ public class BugzillaTaskEditorPage extends AbstractTaskEditorPage {
break;
}
}
+ for (TaskEditorPartDescriptor taskEditorPartDescriptor : descriptors) {
+ if (taskEditorPartDescriptor.getId().equals(ID_PART_ATTACHMENTS)) {
+ descriptors.remove(taskEditorPartDescriptor);
+ hasPartAttachments = true;
+ break;
+ }
+ }
// Add Bugzilla Planning part
try {
@@ -157,7 +165,14 @@ public class BugzillaTaskEditorPage extends AbstractTaskEditorPage {
return new BugzillaTaskEditorCommentPart();
}
}.setPath(PATH_COMMENTS));
-
+ }
+ if (hasPartAttachments) {
+ descriptors.add(new TaskEditorPartDescriptor(ID_PART_ATTACHMENTS) {
+ @Override
+ public AbstractTaskEditorPart createPart() {
+ return new BugzillaTaskEditorAttachmentPart();
+ }
+ }.setPath(PATH_ATTACHMENTS));
}
} catch (CoreException e) {
// ignore
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/AttachmentTableLabelProviderTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/AttachmentTableLabelProviderTest.java
index 5226c6e24..b2bda831d 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/AttachmentTableLabelProviderTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/AttachmentTableLabelProviderTest.java
@@ -14,6 +14,13 @@ package org.eclipse.mylyn.tasks.tests.ui.editor;
import junit.framework.TestCase;
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnCreated;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnCreator;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnDefinition;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnDescription;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnID;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnName;
+import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentColumnSize;
import org.eclipse.mylyn.internal.tasks.ui.editors.AttachmentTableLabelProvider;
import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
@@ -22,10 +29,13 @@ import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
* @author Steffen Pingel
*/
public class AttachmentTableLabelProviderTest extends TestCase {
+ private static AttachmentColumnDefinition[] columnDefinitions = { new AttachmentColumnName(0),
+ new AttachmentColumnDescription(1), new AttachmentColumnSize(2), new AttachmentColumnCreator(3),
+ new AttachmentColumnCreated(4), new AttachmentColumnID(5) };
public void testGetAttachmentId() {
TaskAttachment attachment = TaskTestUtil.createMockTaskAttachment("1");
- AttachmentTableLabelProvider labelProvider = new AttachmentTableLabelProvider(null, null);
+ AttachmentTableLabelProvider labelProvider = new AttachmentTableLabelProvider(null, null, columnDefinitions);
attachment.setUrl(null);
assertEquals("", labelProvider.getColumnText(attachment, 5));
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreated.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreated.java
new file mode 100644
index 000000000..08e747f39
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreated.java
@@ -0,0 +1,37 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.swt.SWT;
+
+public class AttachmentColumnCreated extends AttachmentColumnDefinition {
+
+ public AttachmentColumnCreated(int index) {
+ super(index, 100, "Created", SWT.LEFT, true, SWT.DOWN);
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return (attachment.getCreationDate() != null) ? EditorUtil.formatDateTime(attachment.getCreationDate()) : ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return compare(attachment1.getCreationDate(), attachment2.getCreationDate());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreator.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreator.java
new file mode 100644
index 000000000..fd1f6c7c3
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnCreator.java
@@ -0,0 +1,67 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImageManger;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
+import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+
+public class AttachmentColumnCreator extends AttachmentColumnDefinition {
+ private final CommonImageManger imageManager = new CommonImageManger();
+
+ public AttachmentColumnCreator(int index) {
+ super(index, 100, "Creator", SWT.LEFT, false, SWT.NONE);
+ }
+
+ @Override
+ public Image getColumnImage(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ if (attachment.getAuthor() != null) {
+ return getAuthorImage(attachment.getAuthor(), attachment.getTaskRepository());
+ }
+ return null;
+ }
+
+ /**
+ * 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) {
+ if (repository != null && person != null && person.getPersonId().equals(repository.getUserName())) {
+ return imageManager.getImage(CommonImages.PERSON_ME);
+ } else {
+ return imageManager.getImage(CommonImages.PERSON);
+ }
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return (attachment.getAuthor() != null) ? attachment.getAuthor().toString() : ""; //$NON-NLS-1$
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return compare(attachment1.getAuthor().toString(), attachment2.getAuthor().toString());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDefinition.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDefinition.java
new file mode 100644
index 000000000..7c3d75a51
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDefinition.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.TableViewer;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.swt.graphics.Image;
+
+public abstract class AttachmentColumnDefinition {
+
+ protected <T> int compare(Comparable<T> key1, T key2) {
+ if (key1 == null) {
+ return (key2 != null) ? 1 : 0;
+ } else if (key2 == null) {
+ return -1;
+ }
+ return key1.compareTo(key2);
+ }
+
+ private final int index;
+
+ private final int width;
+
+ private final String label;
+
+ private final int alignment;
+
+ private final boolean sortColumn;
+
+ private final int sortDirection;
+
+ public AttachmentColumnDefinition(int index, int width, String label, int alignment, boolean sortColumn,
+ int sortDirection) {
+ super();
+ this.index = index;
+ this.width = width;
+ this.label = label;
+ this.alignment = alignment;
+ this.sortColumn = sortColumn;
+ this.sortDirection = sortDirection;
+ }
+
+ public int getIndex() {
+ return index;
+ }
+
+ public int getWidth() {
+ return width;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public int getAlignment() {
+ return alignment;
+ }
+
+ public boolean isSortColumn() {
+ return sortColumn;
+ }
+
+ public int getSortDirection() {
+ return sortDirection;
+ }
+
+ public Image getColumnImage(ITaskAttachment attachment, int columnIndex) {
+ return null;
+ }
+
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ return ""; //$NON-NLS-1$
+ }
+
+ public abstract int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2,
+ int columnIndex);
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDescription.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDescription.java
new file mode 100644
index 000000000..2512e6f4e
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnDescription.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.swt.SWT;
+
+public class AttachmentColumnDescription extends AttachmentColumnDefinition {
+ public AttachmentColumnDescription(int index) {
+ super(index, 150, "Description", SWT.LEFT, false, SWT.NONE);
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return attachment.getDescription();
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return compare(attachment1.getDescription(), attachment2.getDescription());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnID.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnID.java
new file mode 100644
index 000000000..003baa641
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnID.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.swt.SWT;
+
+public class AttachmentColumnID extends AttachmentColumnDefinition {
+ TaskKeyComparator keyComparator = new TaskKeyComparator();
+
+ public AttachmentColumnID(int index) {
+ super(index, 0, "ID", SWT.LEFT, false, SWT.NONE);
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return getAttachmentId(attachment);
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ String key1 = getAttachmentId(attachment1);
+ String key2 = getAttachmentId(attachment2);
+ return keyComparator.compare2(key1, key2);
+ }
+
+ static String getAttachmentId(ITaskAttachment attachment) {
+ TaskAttribute attribute = attachment.getTaskAttribute();
+ if (attribute != null) {
+ return attribute.getValue();
+ }
+ return ""; //$NON-NLS-1$
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnName.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnName.java
new file mode 100644
index 000000000..b07673a84
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnName.java
@@ -0,0 +1,59 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImageManger;
+import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.mylyn.tasks.ui.TasksUiImages;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Image;
+
+public class AttachmentColumnName extends AttachmentColumnDefinition {
+ private final CommonImageManger imageManager = new CommonImageManger();
+
+ public AttachmentColumnName(int index) {
+ super(index, 130, "Name", SWT.LEFT, false, SWT.NONE);
+ }
+
+ @Override
+ public Image getColumnImage(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ if (AttachmentUtil.isContext(attachment)) {
+ return imageManager.getImage(TasksUiImages.CONTEXT_TRANSFER);
+ } else if (attachment.isPatch()) {
+ return imageManager.getImage(TasksUiImages.TASK_ATTACHMENT_PATCH);
+ } else {
+ return imageManager.getFileImage(attachment.getFileName());
+ }
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ if (AttachmentUtil.isContext(attachment)) {
+ return "Task Context";
+ } else if (attachment.isPatch()) {
+ return "Patch";
+ } else {
+ return " " + attachment.getFileName(); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return compare(attachment1.getFileName(), attachment2.getFileName());
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnSize.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnSize.java
new file mode 100644
index 000000000..374aa5106
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentColumnSize.java
@@ -0,0 +1,43 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.core.runtime.Assert;
+import org.eclipse.jface.viewers.TableViewer;
+import org.eclipse.mylyn.tasks.core.ITaskAttachment;
+import org.eclipse.swt.SWT;
+
+public class AttachmentColumnSize extends AttachmentColumnDefinition {
+ private final AttachmentSizeFormatter sizeFormatter = AttachmentSizeFormatter.getInstance();
+
+ public AttachmentColumnSize(int index) {
+ super(index, 70, "Size", SWT.RIGHT, false, SWT.NONE);
+ }
+
+ @Override
+ public String getColumnText(ITaskAttachment attachment, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ Long length = attachment.getLength();
+ if (length < 0) {
+ return "-"; //$NON-NLS-1$
+ }
+ return sizeFormatter.format(length);
+
+ }
+
+ @Override
+ public int compare(TableViewer viewer, ITaskAttachment attachment1, ITaskAttachment attachment2, int columnIndex) {
+ Assert.isTrue(columnIndex == getIndex());
+ return compare(attachment1.getLength(), attachment2.getLength());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java
index a4c2d7e2a..b2b3149d7 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java
@@ -16,15 +16,9 @@ package org.eclipse.mylyn.internal.tasks.ui.editors;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ViewerCell;
-import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImageManger;
-import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonThemes;
-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;
@@ -39,92 +33,27 @@ import org.eclipse.ui.themes.IThemeManager;
*/
public class AttachmentTableLabelProvider extends ColumnLabelProvider {
- private final AttachmentSizeFormatter sizeFormatter = AttachmentSizeFormatter.getInstance();
-
private final TaskDataModel model;
private final AttributeEditorToolkit attributeEditorToolkit;
- private final CommonImageManger imageManager;
+ private final AttachmentColumnDefinition[] definitions;
- public AttachmentTableLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit) {
+ public AttachmentTableLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit,
+ AttachmentColumnDefinition[] definitions) {
this.model = model;
this.attributeEditorToolkit = attributeEditorToolkit;
- this.imageManager = new CommonImageManger();
+ this.definitions = definitions;
}
public Image getColumnImage(Object element, int columnIndex) {
ITaskAttachment attachment = (ITaskAttachment) element;
- if (columnIndex == 0) {
- if (AttachmentUtil.isContext(attachment)) {
- return imageManager.getImage(TasksUiImages.CONTEXT_TRANSFER);
- } else if (attachment.isPatch()) {
- return imageManager.getImage(TasksUiImages.TASK_ATTACHMENT_PATCH);
- } else {
- return imageManager.getFileImage(attachment.getFileName());
- }
- } else if (columnIndex == 3 && attachment.getAuthor() != null) {
- return getAuthorImage(attachment.getAuthor(), attachment.getTaskRepository());
- }
- return null;
- }
-
- /**
- * 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) {
- if (repository != null && person != null && person.getPersonId().equals(repository.getUserName())) {
- return imageManager.getImage(CommonImages.PERSON_ME);
- } else {
- return imageManager.getImage(CommonImages.PERSON);
- }
+ return definitions[columnIndex].getColumnImage(attachment, columnIndex);
}
public String getColumnText(Object element, int columnIndex) {
ITaskAttachment attachment = (ITaskAttachment) element;
- switch (columnIndex) {
- case 0:
- if (AttachmentUtil.isContext(attachment)) {
- return Messages.AttachmentTableLabelProvider_Task_Context;
- } else if (attachment.isPatch()) {
- return 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())
- : ""; //$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$
+ return definitions[columnIndex].getColumnText(attachment, columnIndex);
}
@Override
@@ -133,11 +62,6 @@ public class AttachmentTableLabelProvider extends ColumnLabelProvider {
}
@Override
- public void dispose() {
- imageManager.dispose();
- }
-
- @Override
public boolean isLabelProperty(Object element, String property) {
// ignore
return false;
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java
index dbeb1053b..b98028d12 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java
@@ -41,7 +41,6 @@ import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
-import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
@@ -73,47 +72,27 @@ import org.eclipse.ui.forms.widgets.Section;
* @author Steffen Pingel
*/
public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
+ public AttachmentColumnDefinition[] columnDefinitions;
- private class AttachmentTableSorter extends TableSorter {
+ public AttachmentColumnDefinition[] getColumnDefinitions() {
+ return new AttachmentColumnDefinition[] { new AttachmentColumnName(0), new AttachmentColumnDescription(1),
+ new AttachmentColumnSize(2), new AttachmentColumnCreator(3), new AttachmentColumnCreated(4),
+ new AttachmentColumnID(5) };
+ }
- TaskKeyComparator keyComparator = new TaskKeyComparator();
+ private class AttachmentTableSorter extends TableSorter {
@Override
public int compare(TableViewer viewer, Object e1, Object e2, int columnIndex) {
ITaskAttachment attachment1 = (ITaskAttachment) e1;
ITaskAttachment attachment2 = (ITaskAttachment) e2;
- switch (columnIndex) {
- case 0:
- return compare(attachment1.getFileName(), attachment2.getFileName());
- case 1:
- String description1 = attachment1.getDescription();
- String description2 = attachment2.getDescription();
- return compare(description1, description2);
- case 2:
- return compare(attachment1.getLength(), attachment2.getLength());
- case 3:
- return compare(attachment1.getAuthor().toString(), attachment2.getAuthor().toString());
- case 4:
- return compare(attachment1.getCreationDate(), attachment2.getCreationDate());
- case 5:
- String key1 = AttachmentTableLabelProvider.getAttachmentId(attachment1);
- String key2 = AttachmentTableLabelProvider.getAttachmentId(attachment2);
- return keyComparator.compare2(key1, key2);
- }
- return super.compare(viewer, e1, e2, columnIndex);
+ return columnDefinitions[columnIndex].compare(viewer, attachment1, attachment2, columnIndex);
}
}
private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
- private final String[] attachmentsColumns = { Messages.TaskEditorAttachmentPart_Name,
- Messages.TaskEditorAttachmentPart_Description, /*"Type", */Messages.TaskEditorAttachmentPart_Size,
- Messages.TaskEditorAttachmentPart_Creator, Messages.TaskEditorAttachmentPart_Created,
- Messages.TaskEditorAttachmentPart_ID };
-
- private final int[] attachmentsColumnWidths = { 130, 150, /*100,*/70, 100, 100, 0 };
-
private List<TaskAttribute> attachments;
private boolean hasIncoming;
@@ -126,6 +105,7 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
public TaskEditorAttachmentPart() {
setPartName(Messages.TaskEditorAttachmentPart_Attachments);
+ columnDefinitions = getColumnDefinitions();
}
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
@@ -140,18 +120,19 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
.applyTo(attachmentsTable);
attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
- for (int i = 0; i < attachmentsColumns.length; i++) {
+ String[] attachmentsColumns = new String[columnDefinitions.length];
+ for (int i = 0; i < columnDefinitions.length; i++) {
TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
- column.setText(attachmentsColumns[i]);
- column.setWidth(attachmentsColumnWidths[i]);
+ column.setText(columnDefinitions[i].getLabel());
+ attachmentsColumns[i] = columnDefinitions[i].getLabel();
+ column.setWidth(columnDefinitions[i].getWidth());
+ column.setAlignment(columnDefinitions[i].getAlignment());
column.setMoveable(true);
- if (i == 4) {
+ if (columnDefinitions[i].isSortColumn()) {
attachmentsTable.setSortColumn(column);
- attachmentsTable.setSortDirection(SWT.DOWN);
+ attachmentsTable.setSortDirection(columnDefinitions[i].getSortDirection());
}
}
- // size column
- attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT);
TableViewer attachmentsViewer = new TableViewer(attachmentsTable);
attachmentsViewer.setUseHashlookup(true);
@@ -169,7 +150,7 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
}
attachmentsViewer.setContentProvider(new ArrayContentProvider());
attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(),
- getTaskEditorPage().getAttributeEditorToolkit()));
+ getTaskEditorPage().getAttributeEditorToolkit(), columnDefinitions));
attachmentsViewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
openAttachments(event);

Back to the top