Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2016-01-11 18:20:23 -0500
committerGerrit Code Review @ Eclipse.org2016-01-11 18:43:01 -0500
commit43b0a1d218872d346e2304145d92556e794d475f (patch)
tree79f74752590d01e2796663a493fbc284ab002e74 /org.eclipse.mylyn.reviews.ui/src
parent86fbddf81816cbb3380c3363e27dbaf89c9495f0 (diff)
downloadorg.eclipse.mylyn.reviews-43b0a1d218872d346e2304145d92556e794d475f.tar.gz
org.eclipse.mylyn.reviews-43b0a1d218872d346e2304145d92556e794d475f.tar.xz
org.eclipse.mylyn.reviews-43b0a1d218872d346e2304145d92556e794d475f.zip
support sorting columns in reviews table
Diffstat (limited to 'org.eclipse.mylyn.reviews.ui/src')
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewColumnLabelProvider.java13
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java62
2 files changed, 72 insertions, 3 deletions
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewColumnLabelProvider.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewColumnLabelProvider.java
index 5b0678eb..1205db79 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewColumnLabelProvider.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewColumnLabelProvider.java
@@ -113,6 +113,19 @@ public class ReviewColumnLabelProvider extends ColumnLabelProvider {
}
}
+ public String getSortString(Object element, int columnIndex) {
+ TaskReview reviewContainer = (TaskReview) element;
+
+ switch (columnIndex) {
+ case CODE_REVIEW_COLUMN:
+ return Integer.toString(reviewContainer.getCodeReviewScore());
+ case VERIFIED_COLUMN:
+ return Integer.toString(reviewContainer.getVerifiedScore());
+ default:
+ return getColumnText(element, columnIndex);
+ }
+ }
+
@Override
public String getToolTipText(Object element) {
TaskReview review = (TaskReview) element;
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java
index 86ab5a67..71cd5400 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java
@@ -24,6 +24,7 @@ import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.window.ToolTip;
import org.eclipse.mylyn.commons.ui.SelectionProviderAdapter;
+import org.eclipse.mylyn.commons.ui.TableSorter;
import org.eclipse.mylyn.internal.reviews.ui.ReviewColumnLabelProvider;
import org.eclipse.mylyn.internal.reviews.ui.ReviewsUiPlugin;
import org.eclipse.mylyn.internal.tasks.core.TaskList;
@@ -35,6 +36,8 @@ import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.ui.TasksUiUtil;
import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
import org.eclipse.swt.SWT;
+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;
@@ -48,6 +51,38 @@ import org.eclipse.ui.forms.widgets.Section;
*/
public class TaskEditorReviewsPart extends AbstractTaskEditorPart {
+ private static final class ReviewColumnSorter extends TableSorter {
+ private final ReviewColumnLabelProvider labelProvider;
+
+ public ReviewColumnSorter(ReviewColumnLabelProvider labelProvider) {
+ this.labelProvider = labelProvider;
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public int compare(TableViewer viewer, Object e1, Object e2, int columnIndex) {
+ int cat1 = category(e1);
+ int cat2 = category(e2);
+
+ if (cat1 != cat2) {
+ return cat1 - cat2;
+ }
+
+ String name1 = labelProvider.getSortString(e1, columnIndex);
+ String name2 = labelProvider.getSortString(e2, columnIndex);
+
+ if (name1 == null) {
+ name1 = "";//$NON-NLS-1$
+ }
+ if (name2 == null) {
+ name2 = "";//$NON-NLS-1$
+ }
+
+ // use the comparator to compare the strings
+ return getComparator().compare(name1, name2);
+ }
+ }
+
private static final String ID_TASK_EDITOR_REVIEWS_PART = "org.eclipse.mylyn.internal.reviews.ui.editor.parts.TaskEditorReviewsPart"; //$NON-NLS-1$
private Composite reviewsComposite;
@@ -146,21 +181,42 @@ public class TaskEditorReviewsPart extends AbstractTaskEditorPart {
.applyTo(reviewsTable);
reviewsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
+ reviewsViewer = new TableViewer(reviewsTable);
for (int i = 0; i < REVIEWS_COLUMNS.length; i++) {
- TableColumn column = new TableColumn(reviewsTable, SWT.LEFT, i);
+ final TableColumn column = new TableColumn(reviewsTable, SWT.LEFT, i);
column.setText(REVIEWS_COLUMNS[i]);
column.setWidth(REVIEWS_COLUMNS_WIDTH[i]);
column.setMoveable(true);
+ column.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ int direction = reviewsTable.getSortDirection();
+ if (reviewsTable.getSortColumn() == column && direction != SWT.NONE) {
+ direction = (direction == SWT.DOWN) ? SWT.UP : SWT.NONE;
+ } else {
+ direction = SWT.DOWN;
+ }
+
+ reviewsTable.setSortDirection(direction);
+ if (direction == SWT.NONE) {
+ reviewsTable.setSortColumn(null);
+ } else {
+ reviewsTable.setSortColumn(column);
+ }
+ reviewsViewer.refresh();
+ }
+ });
}
- reviewsViewer = new TableViewer(reviewsTable);
reviewsViewer.setUseHashlookup(true);
reviewsViewer.setColumnProperties(REVIEWS_COLUMNS);
ColumnViewerToolTipSupport.enableFor(reviewsViewer, ToolTip.NO_RECREATE);
reviewsViewer.setContentProvider(new ArrayContentProvider());
- reviewsViewer.setLabelProvider(new ReviewColumnLabelProvider());
+ ReviewColumnLabelProvider labelProvider = new ReviewColumnLabelProvider();
+ reviewsViewer.setLabelProvider(labelProvider);
+ reviewsViewer.setComparator(new ReviewColumnSorter(labelProvider));
reviewsViewer.addOpenListener(new IOpenListener() {
public void open(OpenEvent event) {

Back to the top