|
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) { |