|
Lines 29-42
Link Here
|
| 29 |
import org.eclipse.jface.viewers.OpenEvent; |
29 |
import org.eclipse.jface.viewers.OpenEvent; |
| 30 |
import org.eclipse.jface.viewers.StructuredSelection; |
30 |
import org.eclipse.jface.viewers.StructuredSelection; |
| 31 |
import org.eclipse.jface.viewers.Viewer; |
31 |
import org.eclipse.jface.viewers.Viewer; |
| 32 |
import org.eclipse.jface.viewers.ViewerSorter; |
|
|
| 33 |
import org.eclipse.jface.window.ToolTip; |
32 |
import org.eclipse.jface.window.ToolTip; |
| 34 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
33 |
import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; |
| 35 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
34 |
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; |
| 36 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; |
35 |
import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; |
| 37 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
36 |
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; |
| 38 |
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; |
37 |
import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; |
|
|
38 |
import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; |
| 39 |
import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState; |
39 |
import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState; |
|
|
40 |
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableSorter; |
| 40 |
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator; |
41 |
import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator; |
| 41 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
42 |
import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; |
| 42 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
43 |
import org.eclipse.mylyn.tasks.core.ITaskAttachment; |
|
Lines 79-85
Link Here
|
| 79 |
private class AttachmentTableViewer extends AbstractTableViewerConfigurator { |
80 |
private class AttachmentTableViewer extends AbstractTableViewerConfigurator { |
| 80 |
public AttachmentTableViewer(File stateFile) { |
81 |
public AttachmentTableViewer(File stateFile) { |
| 81 |
super(stateFile); |
82 |
super(stateFile); |
| 82 |
// ignore |
|
|
| 83 |
} |
83 |
} |
| 84 |
|
84 |
|
| 85 |
@Override |
85 |
@Override |
|
Lines 118-141
Link Here
|
| 118 |
tableViewer.setUseHashlookup(true); |
118 |
tableViewer.setUseHashlookup(true); |
| 119 |
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE); |
119 |
ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE); |
| 120 |
|
120 |
|
| 121 |
tableViewer.setSorter(new ViewerSorter() { |
121 |
tableViewer.setSorter(tableSorter); |
| 122 |
@Override |
|
|
| 123 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 124 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
| 125 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
| 126 |
Date created1 = attachment1.getCreationDate(); |
| 127 |
Date created2 = attachment2.getCreationDate(); |
| 128 |
if (created1 != null && created2 != null) { |
| 129 |
return created1.compareTo(created2); |
| 130 |
} else if (created1 == null && created2 != null) { |
| 131 |
return -1; |
| 132 |
} else if (created1 != null && created2 == null) { |
| 133 |
return 1; |
| 134 |
} else { |
| 135 |
return 0; |
| 136 |
} |
| 137 |
} |
| 138 |
}); |
| 139 |
List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); |
122 |
List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); |
| 140 |
for (TaskAttribute attribute : attachments) { |
123 |
for (TaskAttribute attribute : attachments) { |
| 141 |
TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), |
124 |
TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), |
|
Lines 159-164
Link Here
|
| 159 |
tableViewer.setInput(attachmentList.toArray()); |
142 |
tableViewer.setInput(attachmentList.toArray()); |
| 160 |
} |
143 |
} |
| 161 |
} |
144 |
} |
|
|
145 |
|
| 146 |
@Override |
| 147 |
protected AbstractTableSorter createTableSorter() { |
| 148 |
|
| 149 |
return new AbstractTableSorter() { |
| 150 |
|
| 151 |
@Override |
| 152 |
public void setDefault() { |
| 153 |
propertyIndex = 5; |
| 154 |
direction = SWT.UP; |
| 155 |
} |
| 156 |
|
| 157 |
@Override |
| 158 |
public int compare(Viewer viewer, Object e1, Object e2) { |
| 159 |
int erg = 0; |
| 160 |
ITaskAttachment attachment1 = (ITaskAttachment) e1; |
| 161 |
ITaskAttachment attachment2 = (ITaskAttachment) e2; |
| 162 |
switch (propertyIndex) { |
| 163 |
case 0: |
| 164 |
String id1 = attachment1.getUrl(); |
| 165 |
String id2 = attachment2.getUrl(); |
| 166 |
int i = id1.indexOf("?id="); //$NON-NLS-1$ |
| 167 |
if (i != -1) { |
| 168 |
id1 = id1.substring(i + 4); |
| 169 |
} else { |
| 170 |
id1 = ""; //$NON-NLS-1$ |
| 171 |
} |
| 172 |
i = id2.indexOf("?id="); //$NON-NLS-1$ |
| 173 |
if (i != -1) { |
| 174 |
id2 = id2.substring(i + 4); |
| 175 |
} else { |
| 176 |
id2 = ""; //$NON-NLS-1$ |
| 177 |
} |
| 178 |
|
| 179 |
erg = id1.length() - id2.length(); |
| 180 |
if (erg == 0) { |
| 181 |
erg = id1.compareTo(id2); |
| 182 |
} |
| 183 |
break; |
| 184 |
|
| 185 |
case 1: |
| 186 |
String type1 = attachment1.getFileName(); |
| 187 |
String type2 = attachment2.getFileName(); |
| 188 |
if (AttachmentUtil.isContext(attachment1)) { |
| 189 |
type1 = Messages.AttachmentTableLabelProvider_Task_Context; |
| 190 |
} else if (attachment1.isPatch()) { |
| 191 |
type1 = Messages.AttachmentTableLabelProvider_Patch; |
| 192 |
} |
| 193 |
if (AttachmentUtil.isContext(attachment2)) { |
| 194 |
type2 = Messages.AttachmentTableLabelProvider_Task_Context; |
| 195 |
} else if (attachment2.isPatch()) { |
| 196 |
type2 = Messages.AttachmentTableLabelProvider_Patch; |
| 197 |
} |
| 198 |
erg = type1.compareTo(type2); |
| 199 |
break; |
| 200 |
case 2: |
| 201 |
String description1 = attachment1.getDescription(); |
| 202 |
String description2 = attachment2.getDescription(); |
| 203 |
erg = description1.compareTo(description2); |
| 204 |
break; |
| 205 |
case 3: |
| 206 |
Long length1 = attachment1.getLength(); |
| 207 |
Long idLength2 = attachment2.getLength(); |
| 208 |
length1 = length1 < 0 ? 0 : length1; |
| 209 |
idLength2 = idLength2 < 0 ? 0 : idLength2; |
| 210 |
erg = length1.compareTo(idLength2); |
| 211 |
break; |
| 212 |
case 4: |
| 213 |
String author1 = attachment1.getAuthor().toString(); |
| 214 |
String author2 = attachment2.getAuthor().toString(); |
| 215 |
erg = author1.compareTo(author2); |
| 216 |
break; |
| 217 |
case 5: |
| 218 |
Date created1 = attachment1.getCreationDate(); |
| 219 |
Date created2 = attachment2.getCreationDate(); |
| 220 |
if (created1 != null && created2 != null) { |
| 221 |
erg = created1.compareTo(created2); |
| 222 |
} else if (created1 == null && created2 != null) { |
| 223 |
erg = -1; |
| 224 |
} else if (created1 != null && created2 == null) { |
| 225 |
erg = 1; |
| 226 |
} else { |
| 227 |
erg = 0; |
| 228 |
} |
| 229 |
break; |
| 230 |
} |
| 231 |
// If descending order, flip the direction |
| 232 |
if (direction == DESCENDING) { |
| 233 |
erg = -erg; |
| 234 |
} |
| 235 |
return erg; |
| 236 |
} |
| 237 |
}; |
| 238 |
} |
| 162 |
} |
239 |
} |
| 163 |
|
240 |
|
| 164 |
private AttachmentTableViewer attachmentsViewer; |
241 |
private AttachmentTableViewer attachmentsViewer; |