Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrank Becker2016-10-20 08:29:49 +0000
committerGerrit Code Review @ Eclipse.org2016-12-14 19:52:31 +0000
commit3cfc9e4eeb62e9b9811c654ea4f85f2b1d472d3e (patch)
treeac9a32e8522a004a9fbd07819db5401d5b18cb45
parent3f4a4276bc7dd0341f4900ded2d6cf8708e96a96 (diff)
downloadorg.eclipse.mylyn.tasks-3cfc9e4eeb62e9b9811c654ea4f85f2b1d472d3e.tar.gz
org.eclipse.mylyn.tasks-3cfc9e4eeb62e9b9811c654ea4f85f2b1d472d3e.tar.xz
org.eclipse.mylyn.tasks-3cfc9e4eeb62e9b9811c654ea4f85f2b1d472d3e.zip
505598: TaskEditorAttachmentPart should use
ConfigurableColumnTableViewerSupport Change-Id: Ie21e7465068654978c04b1ee57d40ec19c44d176 Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=505598
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/editor/AttachmentTableLabelProviderTest.java16
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/AttachmentTableLabelProvider.java203
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java177
3 files changed, 214 insertions, 182 deletions
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 772880dae..7497e955b 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
@@ -11,12 +11,12 @@
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.AttachmentTableLabelProvider;
import org.eclipse.mylyn.tasks.tests.TaskTestUtil;
+import junit.framework.TestCase;
+
/**
* @author Thomas Ehrnhoefer
* @author Steffen Pingel
@@ -25,22 +25,22 @@ public class AttachmentTableLabelProviderTest extends TestCase {
public void testGetAttachmentId() {
TaskAttachment attachment = TaskTestUtil.createMockTaskAttachment("1");
- AttachmentTableLabelProvider labelProvider = new AttachmentTableLabelProvider(null, null);
+ AttachmentTableLabelProvider labelProvider = new AttachmentTableLabelProvider();
attachment.setUrl(null);
- assertEquals("", labelProvider.getColumnText(attachment, 5));
+ assertEquals("", labelProvider.buildTextFromEventIndex(5, attachment).getString());
attachment.setUrl("");
- assertEquals("", labelProvider.getColumnText(attachment, 5));
+ assertEquals("", labelProvider.buildTextFromEventIndex(5, attachment).getString());
attachment.setUrl("http://testi.ng");
- assertEquals("", labelProvider.getColumnText(attachment, 5));
+ assertEquals("", labelProvider.buildTextFromEventIndex(5, attachment).getString());
attachment.setUrl("http://testi.ng/?some=parameter");
- assertEquals("", labelProvider.getColumnText(attachment, 5));
+ assertEquals("", labelProvider.buildTextFromEventIndex(5, attachment).getString());
attachment.setUrl("http://testi.ng/?id=myid");
- assertEquals("myid", labelProvider.getColumnText(attachment, 5));
+ assertEquals("myid", labelProvider.buildTextFromEventIndex(5, attachment).getString());
}
}
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 568ae86a9..d667a8a41 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
@@ -13,44 +13,78 @@
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.ColumnViewer;
+import org.eclipse.jface.viewers.StyledCellLabelProvider;
+import org.eclipse.jface.viewers.StyledString;
+import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.mylyn.commons.ui.CommonImages;
-import org.eclipse.mylyn.commons.ui.compatibility.CommonThemes;
+import org.eclipse.mylyn.commons.ui.TableColumnDescriptor;
import org.eclipse.mylyn.commons.workbench.CommonImageManger;
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;
import org.eclipse.swt.graphics.Point;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.themes.IThemeManager;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.TableColumn;
/**
* @author Mik Kersten
* @author Steffen Pingel
* @author Kevin Sawicki
*/
-public class AttachmentTableLabelProvider extends ColumnLabelProvider {
+public class AttachmentTableLabelProvider extends StyledCellLabelProvider {
private final AttachmentSizeFormatter sizeFormatter = AttachmentSizeFormatter.getInstance();
- private final TaskDataModel model;
+ private final CommonImageManger imageManager = new CommonImageManger();
- private final AttributeEditorToolkit attributeEditorToolkit;
+ @Override
+ public void update(ViewerCell cell) {
+ cell.setImage(getColumnImage((ITaskAttachment) cell.getElement(), cell.getColumnIndex()));
+ StyledString str = buildTextFromEventIndex(cell.getColumnIndex(), (ITaskAttachment) cell.getElement());
+ cell.setText(str.getString());
+ cell.setStyleRanges(str.getStyleRanges());
+ super.update(cell);
+ }
+
+ @Override
+ protected void measure(Event event, Object element) {
+ super.measure(event, element);
+ measure4MulitlineColumn(event, element);
+ }
+
+ protected void measure4MulitlineColumn(Event event, Object element) {
+ ColumnViewer viewer = getViewer();
+ if (viewer instanceof TableViewer) {
+ TableColumn col = ((TableViewer) viewer).getTable().getColumn(event.index);
+ TableColumnDescriptor colDes = (TableColumnDescriptor) col
+ .getData(TableColumnDescriptor.TABLE_COLUMN_DESCRIPTOR_KEY);
+ if (colDes != null && !colDes.isAutoSize()) {
+ return;
+ }
+ event.width = ((TableViewer) viewer).getTable().getColumn(event.index).getWidth();
+ if (event.width == 0) {
+ return;
+ }
- private final CommonImageManger imageManager;
+ ITaskAttachment attachment = (ITaskAttachment) element;
+ Point size = event.gc.textExtent(buildTextFromEventIndex(event.index, attachment).getString());
+ event.height = size.y;
+ if (event.index == 0 || event.index == 3) {
+ size.x = size.x + 22;
- public AttachmentTableLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit) {
- this.model = model;
- this.attributeEditorToolkit = attributeEditorToolkit;
- this.imageManager = new CommonImageManger();
+ } else {
+ size.x = size.x + 3;
+ }
+ if (size.x > event.width) {
+ event.width = size.x;
+ ((TableViewer) viewer).getTable().getColumn(event.index).setWidth(size.x);
+ }
+ }
}
public Image getColumnImage(Object element, int columnIndex) {
@@ -71,7 +105,7 @@ public class AttachmentTableLabelProvider extends ColumnLabelProvider {
/**
* Get author image for a specified repository person and task repository
- *
+ *
* @param person
* @param repository
* @return author image
@@ -84,39 +118,53 @@ public class AttachmentTableLabelProvider extends ColumnLabelProvider {
}
}
- public String getColumnText(Object element, int columnIndex) {
- ITaskAttachment attachment = (ITaskAttachment) element;
- switch (columnIndex) {
+ public StyledString buildTextFromEventIndex(int index, ITaskAttachment attachment) {
+ StyledString text = new StyledString();
+ switch (index) {
case 0:
if (AttachmentUtil.isContext(attachment)) {
- return Messages.AttachmentTableLabelProvider_Task_Context;
+ text.append(Messages.AttachmentTableLabelProvider_Task_Context);
} else if (attachment.isPatch()) {
- return Messages.AttachmentTableLabelProvider_Patch;
+ text.append(Messages.AttachmentTableLabelProvider_Patch);
} else {
- return " " + attachment.getFileName(); //$NON-NLS-1$
+ text.append(" " + attachment.getFileName()); //$NON-NLS-1$
}
+ break;
case 1:
- return attachment.getDescription();
+ text.append(attachment.getDescription());
+ break;
case 2:
Long length = attachment.getLength();
if (length < 0) {
- return "-"; //$NON-NLS-1$
+ text.append("-"); //$NON-NLS-1$
}
- return sizeFormatter.format(length);
+ text.append(sizeFormatter.format(length));
+ break;
case 3:
- return (attachment.getAuthor() != null) ? attachment.getAuthor().toString() : ""; //$NON-NLS-1$
+ String autherText = (attachment.getAuthor() != null) ? attachment.getAuthor().toString() : ""; //$NON-NLS-1$
+ String[] autherPart = autherText.split(" <"); //$NON-NLS-1$
+ text.append(autherPart[0] + " ", StyledString.COUNTER_STYLER); //$NON-NLS-1$
+ if (autherPart.length > 1) {
+ text.append("<" + autherPart[1], StyledString.COUNTER_STYLER); //$NON-NLS-1$
+ }
+ break;
case 4:
- return (attachment.getCreationDate() != null)
+ text.append((attachment.getCreationDate() != null)
? EditorUtil.formatDateTime(attachment.getCreationDate())
- : ""; //$NON-NLS-1$
+ : ""); //$NON-NLS-1$
+ break;
case 5:
// FIXME add id to ITaskAttachment
- return getAttachmentId(attachment);
+ text.append(getAttachmentId(attachment));
+ break;
+ default:
+ text.append("unrecognized column");
+ break;
}
- return "unrecognized column"; //$NON-NLS-1$
+ return text;
}
- static String getAttachmentId(ITaskAttachment attachment) {
+ public static String getAttachmentId(ITaskAttachment attachment) {
String a = attachment.getUrl();
if (a != null) {
int i = a.indexOf("?id="); //$NON-NLS-1$
@@ -127,93 +175,4 @@ public class AttachmentTableLabelProvider extends ColumnLabelProvider {
return ""; //$NON-NLS-1$
}
- @Override
- public void addListener(ILabelProviderListener listener) {
- // ignore
- }
-
- @Override
- public void dispose() {
- imageManager.dispose();
- }
-
- @Override
- public boolean isLabelProperty(Object element, String property) {
- // ignore
- return false;
- }
-
- @Override
- public void removeListener(ILabelProviderListener listener) {
- // ignore
- }
-
- @Override
- public Color getForeground(Object element) {
- ITaskAttachment att = (ITaskAttachment) element;
- if (att.isDeprecated()) {
- IThemeManager themeManager = PlatformUI.getWorkbench().getThemeManager();
- return themeManager.getCurrentTheme().getColorRegistry().get(CommonThemes.COLOR_COMPLETED);
- }
- return super.getForeground(element);
- }
-
- @Override
- public String getToolTipText(Object element) {
- ITaskAttachment attachment = (ITaskAttachment) element;
- StringBuilder sb = new StringBuilder();
- sb.append(Messages.AttachmentTableLabelProvider_File_);
- sb.append(attachment.getFileName());
- if (attachment.getContentType() != null) {
- sb.append("\n"); //$NON-NLS-1$
- sb.append(Messages.AttachmentTableLabelProvider_Type_);
- sb.append(attachment.getContentType());
- }
- return sb.toString();
- /*"\nFilename\t\t" + attachment.getAttributeValue("filename")
- +"ID\t\t\t" + attachment.getAttributeValue("attachid")
- + "\nDate\t\t\t" + attachment.getAttributeValue("date")
- + "\nDescription\t" + attachment.getAttributeValue("desc")
- + "\nCreator\t\t" + attachment.getCreator()
- + "\nType\t\t\t" + attachment.getAttributeValue("type")
- + "\nURL\t\t\t" + attachment.getAttributeValue("task.common.attachment.url");*/
- }
-
- @Override
- public Point getToolTipShift(Object object) {
- return new Point(5, 5);
- }
-
- @Override
- public int getToolTipDisplayDelayTime(Object object) {
- return 200;
- }
-
- @Override
- public int getToolTipTimeDisplayed(Object object) {
- return 5000;
- }
-
- @Override
- public void update(ViewerCell cell) {
- Object element = cell.getElement();
- cell.setText(getColumnText(element, cell.getColumnIndex()));
- Image image = getColumnImage(element, cell.getColumnIndex());
- cell.setImage(image);
- cell.setBackground(getBackground(element));
- cell.setForeground(getForeground(element));
- cell.setFont(getFont(element));
- }
-
- @Override
- public Color getBackground(Object element) {
- if (model != null && attributeEditorToolkit != null) {
- ITaskAttachment attachment = (ITaskAttachment) element;
- if (model.hasIncomingChanges(attachment.getTaskAttribute())) {
- return attributeEditorToolkit.getColorIncoming();
- }
- }
- return null;
- }
-
-} \ No newline at end of file
+}
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 a85d73a71..88403877c 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
@@ -35,12 +35,13 @@ import org.eclipse.jface.viewers.OpenEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
+import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.jface.viewers.ViewerFilter;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.mylyn.commons.core.CoreUtil;
import org.eclipse.mylyn.commons.ui.CommonImages;
-import org.eclipse.mylyn.commons.ui.TableSorter;
-import org.eclipse.mylyn.commons.ui.TableViewerSupport;
+import org.eclipse.mylyn.commons.ui.ConfigurableColumnTableViewerSupport;
+import org.eclipse.mylyn.commons.ui.TableColumnDescriptor;
import org.eclipse.mylyn.commons.workbench.forms.CommonFormUtil;
import org.eclipse.mylyn.internal.tasks.core.TaskAttachment;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
@@ -80,35 +81,41 @@ import org.eclipse.ui.forms.widgets.Section;
*/
public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
- private class AttachmentTableSorter extends TableSorter {
+ private class AttachmentTableViewerComparator extends ViewerComparator {
- TaskKeyComparator keyComparator = new TaskKeyComparator();
+ private int propertyIndex;
+
+ private static final int DESCENDING = 1;
+
+ private int direction = DESCENDING;
+
+ public AttachmentTableViewerComparator() {
+ this.propertyIndex = 0;
+ direction = DESCENDING;
+ }
+
+ public void setColumn(int column) {
+ if (column == this.propertyIndex) {
+ // Same column as last sort; toggle the direction
+ direction = 1 - direction;
+ } else {
+ // New column; do an ascending sort
+ this.propertyIndex = column;
+ direction = DESCENDING;
+ }
+ }
@Override
- public int compare(TableViewer viewer, Object e1, Object e2, int columnIndex) {
+ public int compare(Viewer viewer, Object e1, Object e2) {
ITaskAttachment attachment1 = (ITaskAttachment) e1;
ITaskAttachment attachment2 = (ITaskAttachment) e2;
- switch (columnIndex) {
- case 0:
- return CoreUtil.compare(attachment1.getFileName(), attachment2.getFileName());
- case 1:
- String description1 = attachment1.getDescription();
- String description2 = attachment2.getDescription();
- return CoreUtil.compare(description1, description2);
- case 2:
- return CoreUtil.compare(attachment1.getLength(), attachment2.getLength());
- case 3:
- String author1 = attachment1.getAuthor() != null ? attachment1.getAuthor().toString() : null;
- String author2 = attachment2.getAuthor() != null ? attachment2.getAuthor().toString() : null;
- return CoreUtil.compare(author1, author2);
- case 4:
- return CoreUtil.compare(attachment1.getCreationDate(), attachment2.getCreationDate());
- case 5:
- String key1 = AttachmentTableLabelProvider.getAttachmentId(attachment1);
- String key2 = AttachmentTableLabelProvider.getAttachmentId(attachment2);
- return keyComparator.compare2(key1, key2);
+ int rc;
+ rc = compareColumn(attachment1, attachment2, propertyIndex);
+ // If descending order, flip the direction
+ if (direction == DESCENDING) {
+ rc = -rc;
}
- return super.compare(viewer, e1, e2, columnIndex);
+ return rc;
}
}
@@ -141,13 +148,6 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
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> attachmentAttributes;
private boolean hasIncoming;
@@ -170,45 +170,75 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
private Action filterDeprecatedAttachmentsAction;
+ TaskKeyComparator keyComparator = new TaskKeyComparator();
+
+ private AttachmentTableViewerComparator comparator;
+
public TaskEditorAttachmentPart() {
setPartName(Messages.TaskEditorAttachmentPart_Attachments);
}
+ protected TableColumnDescriptor[] createColumnDescriptors() {
+ TableColumnDescriptor[] descriptors = new TableColumnDescriptor[6];
+ descriptors[0] = new TableColumnDescriptor(130, Messages.TaskEditorAttachmentPart_Name, SWT.LEFT, false,
+ SWT.None, false);
+ descriptors[1] = new TableColumnDescriptor(150, Messages.TaskEditorAttachmentPart_Description, SWT.LEFT, false,
+ SWT.None, false);
+ descriptors[2] = new TableColumnDescriptor(70, Messages.TaskEditorAttachmentPart_Size, SWT.RIGHT, false,
+ SWT.None, false);
+ descriptors[3] = new TableColumnDescriptor(100, Messages.TaskEditorAttachmentPart_Creator, SWT.LEFT, false,
+ SWT.None, true);
+ descriptors[4] = new TableColumnDescriptor(100, Messages.TaskEditorAttachmentPart_Created, SWT.LEFT, true,
+ SWT.DOWN, false);
+ descriptors[5] = new TableColumnDescriptor(0, Messages.TaskEditorAttachmentPart_ID, SWT.LEFT, false, SWT.None,
+ false);
+
+ return descriptors;
+ }
+
private void createAttachmentTable(FormToolkit toolkit, final Composite attachmentsComposite) {
attachmentsTable = toolkit.createTable(attachmentsComposite, SWT.MULTI | SWT.FULL_SELECTION);
attachmentsTable.setLinesVisible(true);
attachmentsTable.setHeaderVisible(true);
attachmentsTable.setLayout(new GridLayout());
- GridDataFactory.fillDefaults()
- .align(SWT.FILL, SWT.FILL)
- .grab(true, false)
- .hint(500, SWT.DEFAULT)
- .applyTo(attachmentsTable);
+ GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).hint(500, SWT.DEFAULT).applyTo(
+ attachmentsTable);
attachmentsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
- for (int i = 0; i < attachmentsColumns.length; i++) {
- TableColumn column = new TableColumn(attachmentsTable, SWT.LEFT, i);
- column.setText(attachmentsColumns[i]);
- column.setWidth(attachmentsColumnWidths[i]);
+ TableColumnDescriptor[] columnDescriptorArray = createColumnDescriptors();
+ String[] localAttachmentsColumns = new String[columnDescriptorArray.length];
+ for (int i = 0; i < columnDescriptorArray.length; i++) {
+ int index = i;
+ localAttachmentsColumns[i] = columnDescriptorArray[i].getName();
+
+ TableColumn column = new TableColumn(attachmentsTable, columnDescriptorArray[i].getAlignment(), index);
+ column.setText(columnDescriptorArray[i].getName());
+ column.setWidth(columnDescriptorArray[i].getWidth());
column.setMoveable(true);
- if (i == 4) {
+ column.setData(TableColumnDescriptor.TABLE_COLUMN_DESCRIPTOR_KEY, columnDescriptorArray[i]);
+ if (columnDescriptorArray[i].isDefaultSortColumn()) {
attachmentsTable.setSortColumn(column);
- attachmentsTable.setSortDirection(SWT.DOWN);
+ attachmentsTable.setSortDirection(columnDescriptorArray[i].getSortDirection());
}
+ column.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ comparator.setColumn(index);
+ }
+ });
}
- // size column
- attachmentsTable.getColumn(2).setAlignment(SWT.RIGHT);
attachmentsViewer = new TableViewer(attachmentsTable);
attachmentsViewer.setUseHashlookup(true);
- attachmentsViewer.setColumnProperties(attachmentsColumns);
+ attachmentsViewer.setColumnProperties(localAttachmentsColumns);
ColumnViewerToolTipSupport.enableFor(attachmentsViewer, ToolTip.NO_RECREATE);
- attachmentsViewer.setSorter(new AttachmentTableSorter());
+ comparator = createComparator();
+ attachmentsViewer.setComparator(comparator);
attachmentsViewer.setContentProvider(new ArrayContentProvider());
- attachmentsViewer.setLabelProvider(new AttachmentTableLabelProvider(getModel(),
- getTaskEditorPage().getAttributeEditorToolkit()));
+ attachmentsViewer.setLabelProvider(createTableProvider());
attachmentsViewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {
openAttachments(event);
@@ -230,7 +260,7 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
attachmentsViewer.addFilter(tableFilter);
- new TableViewerSupport(attachmentsViewer, getStateFile());
+ new ConfigurableColumnTableViewerSupport(attachmentsViewer, columnDescriptorArray, getStateFile());
}
private File getStateFile() {
@@ -378,8 +408,9 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
private void updateSectionTitle() {
if (tableFilter.isFilterDeprecatedEnabled()) {
- section.setText(NLS.bind(Messages.TaskEditorAttachmentPart_Attachment_Section_Title_X_of_Y, new Object[] {
- LegacyActionTools.escapeMnemonics(getPartName()), nonDeprecatedCount, attachmentAttributes.size() }));
+ section.setText(NLS.bind(Messages.TaskEditorAttachmentPart_Attachment_Section_Title_X_of_Y,
+ new Object[] { LegacyActionTools.escapeMnemonics(getPartName()), nonDeprecatedCount,
+ attachmentAttributes.size() }));
} else {
section.setText(NLS.bind(Messages.TaskEditorAttachmentPart_Attachment_Section_Title_X,
LegacyActionTools.escapeMnemonics(getPartName()), attachmentAttributes.size()));
@@ -456,4 +487,46 @@ public class TaskEditorAttachmentPart extends AbstractTaskEditorPart {
updateSectionTitle();
}
+ protected int compareColumn(ITaskAttachment attachment1, ITaskAttachment attachment2, int propertyIndex) {
+ int rc;
+ switch (propertyIndex) {
+ case 0:
+ rc = CoreUtil.compare(attachment1.getFileName(), attachment2.getFileName());
+ break;
+ case 1:
+ String description1 = attachment1.getDescription();
+ String description2 = attachment2.getDescription();
+ rc = CoreUtil.compare(description1, description2);
+ break;
+ case 2:
+ rc = CoreUtil.compare(attachment1.getLength(), attachment2.getLength());
+ break;
+ case 3:
+ String author1 = attachment1.getAuthor() != null ? attachment1.getAuthor().toString() : null;
+ String author2 = attachment2.getAuthor() != null ? attachment2.getAuthor().toString() : null;
+ rc = CoreUtil.compare(author1, author2);
+ break;
+ case 4:
+ rc = CoreUtil.compare(attachment1.getCreationDate(), attachment2.getCreationDate());
+ break;
+ case 5:
+ String key1 = AttachmentTableLabelProvider.getAttachmentId(attachment1);
+ String key2 = AttachmentTableLabelProvider.getAttachmentId(attachment2);
+ rc = keyComparator.compare2(key1, key2);
+ break;
+ default:
+ rc = 0;
+ break;
+ }
+ return rc;
+ }
+
+ protected AttachmentTableViewerComparator createComparator() {
+ return new AttachmentTableViewerComparator();
+ }
+
+ protected AttachmentTableLabelProvider createTableProvider() {
+ return new AttachmentTableLabelProvider();
+ }
+
}

Back to the top