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