Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 250257 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java (+13 lines)
Lines 121-130 Link Here
121
		case 4:
121
		case 4:
122
			return (attachment.getCreationDate() != null) ? EditorUtil.formatDateTime(attachment.getCreationDate())
122
			return (attachment.getCreationDate() != null) ? EditorUtil.formatDateTime(attachment.getCreationDate())
123
					: ""; //$NON-NLS-1$
123
					: ""; //$NON-NLS-1$
124
		case 5:
125
			// FIXME add id to ITaskAttachment
126
			return getAttachmentId(attachment);
124
		}
127
		}
125
		return "unrecognized column"; //$NON-NLS-1$
128
		return "unrecognized column"; //$NON-NLS-1$
126
	}
129
	}
127
130
131
	static String getAttachmentId(ITaskAttachment attachment) {
132
		String a = attachment.getUrl();
133
		int i = a.indexOf("?id="); //$NON-NLS-1$
134
		if (i != -1) {
135
			return a.substring(i + 4);
136
		} else {
137
			return ""; //$NON-NLS-1$
138
		}
139
	}
140
128
	@Override
141
	@Override
129
	public void addListener(ILabelProviderListener listener) {
142
	public void addListener(ILabelProviderListener listener) {
130
		// ignore
143
		// ignore
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/Messages.java (+2 lines)
Lines 113-118 Link Here
113
113
114
	public static String TaskEditorAttachmentPart_Description;
114
	public static String TaskEditorAttachmentPart_Description;
115
115
116
	public static String TaskEditorAttachmentPart_ID;
117
116
	public static String TaskEditorAttachmentPart_Name;
118
	public static String TaskEditorAttachmentPart_Name;
117
119
118
	public static String TaskEditorAttachmentPart_No_attachments;
120
	public static String TaskEditorAttachmentPart_No_attachments;
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java (-25 / +58 lines)
Lines 13-22 Link Here
13
13
14
package org.eclipse.mylyn.internal.tasks.ui.editors;
14
package org.eclipse.mylyn.internal.tasks.ui.editors;
15
15
16
import java.io.File;
16
import java.util.ArrayList;
17
import java.util.ArrayList;
17
import java.util.Date;
18
import java.util.List;
18
import java.util.List;
19
19
20
import org.eclipse.core.runtime.IPath;
21
import org.eclipse.core.runtime.Platform;
20
import org.eclipse.jface.action.Action;
22
import org.eclipse.jface.action.Action;
21
import org.eclipse.jface.action.IMenuListener;
23
import org.eclipse.jface.action.IMenuListener;
22
import org.eclipse.jface.action.IMenuManager;
24
import org.eclipse.jface.action.IMenuManager;
Lines 29-41 Link Here
29
import org.eclipse.jface.viewers.OpenEvent;
31
import org.eclipse.jface.viewers.OpenEvent;
30
import org.eclipse.jface.viewers.StructuredSelection;
32
import org.eclipse.jface.viewers.StructuredSelection;
31
import org.eclipse.jface.viewers.TableViewer;
33
import org.eclipse.jface.viewers.TableViewer;
32
import org.eclipse.jface.viewers.Viewer;
33
import org.eclipse.jface.viewers.ViewerSorter;
34
import org.eclipse.jface.window.ToolTip;
34
import org.eclipse.jface.window.ToolTip;
35
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
35
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages;
36
import org.eclipse.mylyn.internal.provisional.commons.ui.TableSorter;
37
import org.eclipse.mylyn.internal.provisional.commons.ui.TableViewerSupport;
36
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
38
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
39
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
37
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler;
40
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler;
38
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
41
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiMenus;
42
import org.eclipse.mylyn.internal.tasks.ui.views.TaskKeyComparator;
39
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
43
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode;
40
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
44
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
41
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
45
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
Lines 64-76 Link Here
64
 */
68
 */
65
public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
69
public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
66
70
71
	private class AttachmentTableSorter extends TableSorter {
72
73
		TaskKeyComparator keyComparator = new TaskKeyComparator();
74
75
		@Override
76
		public int compare(TableViewer viewer, Object e1, Object e2, int columnIndex) {
77
			ITaskAttachment attachment1 = (ITaskAttachment) e1;
78
			ITaskAttachment attachment2 = (ITaskAttachment) e2;
79
			switch (columnIndex) {
80
			case 0:
81
				return compare(attachment1.getFileName(), attachment2.getFileName());
82
			case 1:
83
				String description1 = attachment1.getDescription();
84
				String description2 = attachment2.getDescription();
85
				return compare(description1, description2);
86
			case 2:
87
				return compare(attachment1.getLength(), attachment2.getLength());
88
			case 3:
89
				return compare(attachment1.getAuthor().toString(), attachment2.getAuthor().toString());
90
			case 4:
91
				return compare(attachment1.getCreationDate(), attachment2.getCreationDate());
92
			case 5:
93
				String key1 = AttachmentTableLabelProvider.getAttachmentId(attachment1);
94
				String key2 = AttachmentTableLabelProvider.getAttachmentId(attachment2);
95
				return keyComparator.compare2(key1, key2);
96
			}
97
			return super.compare(viewer, e1, e2, columnIndex);
98
		}
99
100
	}
101
67
	private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
102
	private static final String ID_POPUP_MENU = "org.eclipse.mylyn.tasks.ui.editor.menu.attachments"; //$NON-NLS-1$
68
103
69
	private final String[] attachmentsColumns = { Messages.TaskEditorAttachmentPart_Name,
104
	private final String[] attachmentsColumns = { Messages.TaskEditorAttachmentPart_Name,
70
			Messages.TaskEditorAttachmentPart_Description, /*"Type", */Messages.TaskEditorAttachmentPart_Size,
105
			Messages.TaskEditorAttachmentPart_Description, /*"Type", */Messages.TaskEditorAttachmentPart_Size,
71
			Messages.TaskEditorAttachmentPart_Creator, Messages.TaskEditorAttachmentPart_Created };
106
			Messages.TaskEditorAttachmentPart_Creator, Messages.TaskEditorAttachmentPart_Created,
107
			Messages.TaskEditorAttachmentPart_ID };
72
108
73
	private final int[] attachmentsColumnWidths = { 130, 150, /*100,*/70, 100, 100 };
109
	private final int[] attachmentsColumnWidths = { 130, 150, /*100,*/70, 100, 100, 0 };
74
110
75
	private List<TaskAttribute> attachments;
111
	private List<TaskAttribute> attachments;
76
112
Lines 89-102 Link Here
89
		attachmentsTable.setLinesVisible(true);
125
		attachmentsTable.setLinesVisible(true);
90
		attachmentsTable.setHeaderVisible(true);
126
		attachmentsTable.setHeaderVisible(true);
91
		attachmentsTable.setLayout(new GridLayout());
127
		attachmentsTable.setLayout(new GridLayout());
92
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo(
128
		GridDataFactory.fillDefaults()
93
				attachmentsTable);
129
				.align(SWT.FILL, SWT.FILL)
130
				.grab(true, false)
131
				.hint(500, SWT.DEFAULT)
132
				.applyTo(attachmentsTable);
94
		attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
133
		attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
95
134
96
		for (int i = 0; i < attachmentsColumns.length; i++) {
135
		for (int i = 0; i < attachmentsColumns.length; i++) {
97
			TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
136
			TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
98
			column.setText(attachmentsColumns[i]);
137
			column.setText(attachmentsColumns[i]);
99
			column.setWidth(attachmentsColumnWidths[i]);
138
			column.setWidth(attachmentsColumnWidths[i]);
139
			if (i == 4) {
140
				attachmentsTable.setSortColumn(column);
141
				attachmentsTable.setSortDirection(SWT.UP);
142
			}
100
		}
143
		}
101
		// size column
144
		// size column
102
		attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT);
145
		attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT);
Lines 106-129 Link Here
106
		attachmentsViewer.setColumnProperties(attachmentsColumns);
149
		attachmentsViewer.setColumnProperties(attachmentsColumns);
107
		ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);
150
		ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);
108
151
109
		attachmentsViewer.setSorter(new ViewerSorter() {
152
		attachmentsViewer.setSorter(new AttachmentTableSorter());
110
			@Override
111
			public int compare(Viewer viewer, Object e1, Object e2) {
112
				ITaskAttachment attachment1 = (ITaskAttachment) e1;
113
				ITaskAttachment attachment2 = (ITaskAttachment) e2;
114
				Date created1 = attachment1.getCreationDate();
115
				Date created2 = attachment2.getCreationDate();
116
				if (created1 != null && created2 != null) {
117
					return created1.compareTo(created2);
118
				} else if (created1 == null && created2 != null) {
119
					return -1;
120
				} else if (created1 != null && created2 == null) {
121
					return 1;
122
				} else {
123
					return 0;
124
				}
125
			}
126
		});
127
153
128
		List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
154
		List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size());
129
		for (TaskAttribute attribute : attachments) {
155
		for (TaskAttribute attribute : attachments) {
Lines 153-158 Link Here
153
		getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
179
		getTaskEditorPage().getEditorSite().registerContextMenu(ID_POPUP_MENU, menuManager, attachmentsViewer, true);
154
		Menu menu = menuManager.createContextMenu(attachmentsTable);
180
		Menu menu = menuManager.createContextMenu(attachmentsTable);
155
		attachmentsTable.setMenu(menu);
181
		attachmentsTable.setMenu(menu);
182
183
		new TableViewerSupport(attachmentsViewer, getStateFile());
184
	}
185
186
	private File getStateFile() {
187
		IPath stateLocation = Platform.getStateLocation(TasksUiPlugin.getDefault().getBundle());
188
		return stateLocation.append("TaskEditorAttachmentPart.xml").toFile(); //$NON-NLS-1$
156
	}
189
	}
157
190
158
	private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) {
191
	private void createButtons(Composite attachmentsComposite, FormToolkit toolkit) {
(-)src/org/eclipse/mylyn/internal/tasks/ui/editors/messages.properties (+1 lines)
Lines 60-65 Link Here
60
TaskEditorAttachmentPart_Created=Created
60
TaskEditorAttachmentPart_Created=Created
61
TaskEditorAttachmentPart_Creator=Creator
61
TaskEditorAttachmentPart_Creator=Creator
62
TaskEditorAttachmentPart_Description=Description
62
TaskEditorAttachmentPart_Description=Description
63
TaskEditorAttachmentPart_ID=ID
63
TaskEditorAttachmentPart_Name=Name
64
TaskEditorAttachmentPart_Name=Name
64
TaskEditorAttachmentPart_No_attachments=No attachments
65
TaskEditorAttachmentPart_No_attachments=No attachments
65
TaskEditorAttachmentPart_Size=Size
66
TaskEditorAttachmentPart_Size=Size

Return to bug 250257