Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 174092 Details for
Bug 302652
attachment table should be sortable
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
commited patch
302652V1.txt (text/plain), 12.42 KB, created by
Frank Becker
on 2010-07-12 16:15:28 EDT
(
hide
)
Description:
commited patch
Filename:
MIME Type:
Creator:
Frank Becker
Created:
2010-07-12 16:15:28 EDT
Size:
12.42 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.mylyn.tasks.ui >Index: src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java,v >retrieving revision 1.48 >diff -u -r1.48 TaskEditorAttachmentPart.java >--- src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java 11 Jul 2010 18:54:34 -0000 1.48 >+++ src/org/eclipse/mylyn/internal/tasks/ui/editors/TaskEditorAttachmentPart.java 12 Jul 2010 20:11:59 -0000 >@@ -29,14 +29,15 @@ > import org.eclipse.jface.viewers.OpenEvent; > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.viewers.Viewer; >-import org.eclipse.jface.viewers.ViewerSorter; > import org.eclipse.jface.window.ToolTip; > import org.eclipse.mylyn.internal.provisional.commons.ui.CommonImages; > import org.eclipse.mylyn.internal.tasks.core.TaskAttachment; > import org.eclipse.mylyn.internal.tasks.ui.ITasksUiPreferenceConstants; > import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; > import org.eclipse.mylyn.internal.tasks.ui.commands.OpenTaskAttachmentHandler; >+import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; > import org.eclipse.mylyn.internal.tasks.ui.util.ColumnState; >+import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableSorter; > import org.eclipse.mylyn.internal.tasks.ui.views.AbstractTableViewerConfigurator; > import org.eclipse.mylyn.internal.tasks.ui.wizards.TaskAttachmentWizard.Mode; > import org.eclipse.mylyn.tasks.core.ITaskAttachment; >@@ -79,7 +80,6 @@ > private class AttachmentTableViewer extends AbstractTableViewerConfigurator { > public AttachmentTableViewer(File stateFile) { > super(stateFile); >- // ignore > } > > @Override >@@ -118,24 +118,7 @@ > tableViewer.setUseHashlookup(true); > ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE); > >- tableViewer.setSorter(new ViewerSorter() { >- @Override >- public int compare(Viewer viewer, Object e1, Object e2) { >- ITaskAttachment attachment1 = (ITaskAttachment) e1; >- ITaskAttachment attachment2 = (ITaskAttachment) e2; >- Date created1 = attachment1.getCreationDate(); >- Date created2 = attachment2.getCreationDate(); >- if (created1 != null && created2 != null) { >- return created1.compareTo(created2); >- } else if (created1 == null && created2 != null) { >- return -1; >- } else if (created1 != null && created2 == null) { >- return 1; >- } else { >- return 0; >- } >- } >- }); >+ tableViewer.setSorter(tableSorter); > List<ITaskAttachment> attachmentList = new ArrayList<ITaskAttachment>(attachments.size()); > for (TaskAttribute attribute : attachments) { > TaskAttachment taskAttachment = new TaskAttachment(getModel().getTaskRepository(), >@@ -159,6 +142,100 @@ > tableViewer.setInput(attachmentList.toArray()); > } > } >+ >+ @Override >+ protected AbstractTableSorter createTableSorter() { >+ >+ return new AbstractTableSorter() { >+ >+ @Override >+ public void setDefault() { >+ propertyIndex = 5; >+ direction = SWT.UP; >+ } >+ >+ @Override >+ public int compare(Viewer viewer, Object e1, Object e2) { >+ int erg = 0; >+ ITaskAttachment attachment1 = (ITaskAttachment) e1; >+ ITaskAttachment attachment2 = (ITaskAttachment) e2; >+ switch (propertyIndex) { >+ case 0: >+ String id1 = attachment1.getUrl(); >+ String id2 = attachment2.getUrl(); >+ int i = id1.indexOf("?id="); //$NON-NLS-1$ >+ if (i != -1) { >+ id1 = id1.substring(i + 4); >+ } else { >+ id1 = ""; //$NON-NLS-1$ >+ } >+ i = id2.indexOf("?id="); //$NON-NLS-1$ >+ if (i != -1) { >+ id2 = id2.substring(i + 4); >+ } else { >+ id2 = ""; //$NON-NLS-1$ >+ } >+ >+ erg = id1.length() - id2.length(); >+ if (erg == 0) { >+ erg = id1.compareTo(id2); >+ } >+ break; >+ >+ case 1: >+ String type1 = attachment1.getFileName(); >+ String type2 = attachment2.getFileName(); >+ if (AttachmentUtil.isContext(attachment1)) { >+ type1 = Messages.AttachmentTableLabelProvider_Task_Context; >+ } else if (attachment1.isPatch()) { >+ type1 = Messages.AttachmentTableLabelProvider_Patch; >+ } >+ if (AttachmentUtil.isContext(attachment2)) { >+ type2 = Messages.AttachmentTableLabelProvider_Task_Context; >+ } else if (attachment2.isPatch()) { >+ type2 = Messages.AttachmentTableLabelProvider_Patch; >+ } >+ erg = type1.compareTo(type2); >+ break; >+ case 2: >+ String description1 = attachment1.getDescription(); >+ String description2 = attachment2.getDescription(); >+ erg = description1.compareTo(description2); >+ break; >+ case 3: >+ Long length1 = attachment1.getLength(); >+ Long idLength2 = attachment2.getLength(); >+ length1 = length1 < 0 ? 0 : length1; >+ idLength2 = idLength2 < 0 ? 0 : idLength2; >+ erg = length1.compareTo(idLength2); >+ break; >+ case 4: >+ String author1 = attachment1.getAuthor().toString(); >+ String author2 = attachment2.getAuthor().toString(); >+ erg = author1.compareTo(author2); >+ break; >+ case 5: >+ Date created1 = attachment1.getCreationDate(); >+ Date created2 = attachment2.getCreationDate(); >+ if (created1 != null && created2 != null) { >+ erg = created1.compareTo(created2); >+ } else if (created1 == null && created2 != null) { >+ erg = -1; >+ } else if (created1 != null && created2 == null) { >+ erg = 1; >+ } else { >+ erg = 0; >+ } >+ break; >+ } >+ // If descending order, flip the direction >+ if (direction == DESCENDING) { >+ erg = -erg; >+ } >+ return erg; >+ } >+ }; >+ } > } > > private AttachmentTableViewer attachmentsViewer; >Index: src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableSorter.java >=================================================================== >RCS file: src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableSorter.java >diff -N src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableSorter.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableSorter.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * Copyright (c) 2010 Frank Becker and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Frank Becker - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.mylyn.internal.tasks.ui.views; >+ >+import java.io.Serializable; >+ >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerSorter; >+import org.eclipse.ui.IMemento; >+ >+public abstract class AbstractTableSorter extends ViewerSorter implements Serializable { >+ >+ private static final long serialVersionUID = 8048730201424836905L; >+ >+ protected int propertyIndex; >+ >+ protected static final int ASCENDING = 0; >+ >+ protected static final int DESCENDING = 1; >+ >+ protected int direction = DESCENDING; >+ >+ public AbstractTableSorter() { >+ 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 abstract int compare(Viewer viewer, Object e1, Object e2); >+ >+ public abstract void setDefault(); >+ >+ protected int getPropertyIndex() { >+ return propertyIndex; >+ } >+ >+ protected void setPropertyIndex(int propertyIndex) { >+ this.propertyIndex = propertyIndex; >+ } >+ >+ protected int getDirection() { >+ return direction; >+ } >+ >+ protected void setDirection(int direction) { >+ this.direction = direction; >+ } >+ >+ public void saveState(IMemento memento) { >+ IMemento child = memento.createChild("AbstractTableSorter"); //$NON-NLS-1$ >+ child.putInteger("propertyIndex", propertyIndex); //$NON-NLS-1$ >+ child.putInteger("direction", direction); //$NON-NLS-1$ >+ >+ } >+ >+ public void readState(IMemento memento) { >+ IMemento child = memento.getChild("AbstractTableSorter"); //$NON-NLS-1$ >+ if (child != null) { >+ propertyIndex = child.getInteger("propertyIndex"); //$NON-NLS-1$ >+ direction = child.getInteger("direction"); //$NON-NLS-1$ >+ } else { >+ setDefault(); >+ } >+ } >+} >Index: src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableViewerConfigurator.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.mylyn/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableViewerConfigurator.java,v >retrieving revision 1.1 >diff -u -r1.1 AbstractTableViewerConfigurator.java >--- src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableViewerConfigurator.java 11 Jul 2010 18:54:34 -0000 1.1 >+++ src/org/eclipse/mylyn/internal/tasks/ui/views/AbstractTableViewerConfigurator.java 12 Jul 2010 20:12:00 -0000 >@@ -31,6 +31,8 @@ > import org.eclipse.swt.SWT; > import org.eclipse.swt.events.ControlEvent; > import org.eclipse.swt.events.ControlListener; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Table; >@@ -51,15 +53,20 @@ > > protected int[] orderArray; > >+ protected AbstractTableSorter tableSorter; >+ > public AbstractTableViewerConfigurator(File stateFile) { > super(); > this.stateFile = stateFile; >+ this.tableSorter = createTableSorter(); > } > > abstract protected void setDefaultColumnInfos(); > > abstract protected void setupTableViewer(); > >+ abstract protected AbstractTableSorter createTableSorter(); >+ > private void readStateFile() { > if (stateFile.exists()) { > try { >@@ -78,6 +85,7 @@ > for (int i = 0; i < orderStringArray.length; i++) { > orderArray[i] = Integer.parseInt(orderStringArray[i]); > } >+ tableSorter.readState(memento); > } catch (WorkbenchException e) { > StatusHandler.log(new Status(IStatus.WARNING, TasksUiPlugin.ID_PLUGIN, > "The TableViewerState cache could not be read", e)); //$NON-NLS-1$ >@@ -114,6 +122,7 @@ > orderString += colPos; > } > child.putString("order", orderString); //$NON-NLS-1$ >+ tableSorter.saveState(memento); > > try { > FileWriter writer = new FileWriter(stateFile); >@@ -134,22 +143,42 @@ > > public void create(FormToolkit toolkit, Composite parent, int initialColumnCount) { > table = createTable(parent, toolkit); >+ tableViewer = new TableViewer(table); > columnInfos = new ArrayList<ColumnState>(initialColumnCount); > readStateFile(); > if (columnInfos.size() == 0) { > setDefaultColumnInfos(); > } > adjustColumInfos(); >- for (int index = 0; index < columnInfos.size(); index++) { >- ColumnState colState = columnInfos.get(index); >- final TableColumn column = new TableColumn(table, colState.getAlignment(), index); >+ for (int i = 0; i < columnInfos.size(); i++) { >+ final int index = i; >+ ColumnState colState = columnInfos.get(i); >+ final TableColumn column = new TableColumn(table, colState.getAlignment(), i); > column.setText(colState.getName()); > column.setWidth(colState.getWidths()); > column.setMoveable(true); >- column.addControlListener(createColumnControlListener(table, column, index)); >+ column.addControlListener(createColumnControlListener(table, column, i)); >+ column.addSelectionListener(new SelectionAdapter() { >+ @Override >+ public void widgetSelected(SelectionEvent e) { >+ tableSorter.setColumn(index); >+ int dir = table.getSortDirection(); >+ if (table.getSortColumn() == column) { >+ dir = dir == SWT.UP ? SWT.DOWN : SWT.UP; >+ } else { >+ dir = SWT.DOWN; >+ } >+ table.setSortDirection(dir); >+ table.setSortColumn(column); >+ tableViewer.refresh(); >+ writeStateFile(); >+ } >+ }); > } > >- tableViewer = new TableViewer(table); >+ table.setSortDirection(tableSorter.getDirection() == 1 ? SWT.DOWN : SWT.UP); >+ table.setSortColumn(table.getColumn(tableSorter.getPropertyIndex())); >+ > table.setColumnOrder(orderArray); > setupTableViewer(); > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Flags:
eclipse
:
review?
Actions:
View
|
Diff
Attachments on
bug 302652
: 174092 |
174093