Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRatstache2015-11-29 14:46:50 -0500
committerSam Davis2015-12-10 13:04:40 -0500
commit36d843b3c44f879ce8430fc8f52a2cb2e3ece513 (patch)
treec6f91ebefc2a7df7177148789655ebf1e1c0923b /org.eclipse.mylyn.reviews.ui/src
parent7ec7690d253aeafe01625501da8c054cbabbae33 (diff)
downloadorg.eclipse.mylyn.reviews-36d843b3c44f879ce8430fc8f52a2cb2e3ece513.tar.gz
org.eclipse.mylyn.reviews-36d843b3c44f879ce8430fc8f52a2cb2e3ece513.tar.xz
org.eclipse.mylyn.reviews-36d843b3c44f879ce8430fc8f52a2cb2e3ece513.zip
477635: [UCOSP] contribute reviews section to task editor showing
associated reviews. Change-Id: Ia402f09ba35c1181f7871c6a637b2dde9d2229fc Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=477635 Signed-off-by: Ratstache <landonbutterworth@gmail.com>
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.java160
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsImages.java8
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/Messages.java14
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java221
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskReview.java60
-rw-r--r--org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/messages.properties8
6 files changed, 471 insertions, 0 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
new file mode 100644
index 00000000..560644dd
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewColumnLabelProvider.java
@@ -0,0 +1,160 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Landon Butterworth 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:
+ * Landon Butterworth - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.reviews.ui;
+
+import org.eclipse.jface.viewers.ColumnLabelProvider;
+import org.eclipse.jface.viewers.ViewerCell;
+import org.eclipse.mylyn.commons.ui.CommonImages;
+import org.eclipse.mylyn.internal.reviews.ui.editors.parts.TaskReview;
+import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorToolkit;
+import org.eclipse.swt.graphics.Image;
+
+/**
+ * @author Landon Butterworth
+ */
+public class ReviewColumnLabelProvider extends ColumnLabelProvider {
+
+ private final int VERIFIED = 1;
+
+ private final int NOT_VERIFIED = -1;
+
+ private final TaskDataModel model;
+
+ private final AttributeEditorToolkit attributeEditorToolkit;
+
+ private final int DESCRIPTION_COLUMN = 0;
+
+ private final int CODE_REVIEW_COLUMN = 1;
+
+ private final int VERIFIED_COLUMN = 2;
+
+ private final int INCOMING_CHANGES_COLUMN = 3;
+
+ private final int MINUS_TWO = -2;
+
+ private final int MINUS_ONE = -1;
+
+ private final int ZERO = 0;
+
+ private final int PLUS_ONE = 1;
+
+ private final int PLUS_TWO = 2;
+
+ public ReviewColumnLabelProvider(TaskDataModel model, AttributeEditorToolkit attributeEditorToolkit) {
+ this.model = model;
+ this.attributeEditorToolkit = attributeEditorToolkit;
+ }
+
+ public Image getColumnImage(Object element, int columnIndex) {
+ TaskReview reviewContainer = (TaskReview) element;
+
+ switch (columnIndex) {
+ case DESCRIPTION_COLUMN:
+ return getIncomingChangesImage(reviewContainer);
+ case CODE_REVIEW_COLUMN:
+ return getReviewStateImage(reviewContainer);
+ case VERIFIED_COLUMN:
+ return getVerifiedStateImage(reviewContainer);
+ case INCOMING_CHANGES_COLUMN:
+ return CommonImages.getImage(CommonImages.OVERLAY_CLEAR);
+ }
+
+ return null;
+ }
+
+ private Image getIncomingChangesImage(TaskReview reviewContainer) {
+ if (reviewContainer.getSyncState() == SynchronizationState.INCOMING) {
+ return CommonImages.getImage(CommonImages.OVERLAY_SYNC_INCOMMING);
+ } else if (reviewContainer.getSyncState() == SynchronizationState.INCOMING_NEW) {
+ return CommonImages.getImage(CommonImages.OVERLAY_SYNC_INCOMMING_NEW);
+ }
+
+ return CommonImages.getImage(CommonImages.OVERLAY_CLEAR);
+ }
+
+ private Image getReviewStateImage(TaskReview reviewContainer) {
+ int reviewScore = reviewContainer.getCodeReviewScore();
+
+ switch (reviewScore) {
+ case MINUS_TWO:
+ return CommonImages.getImage(ReviewsImages.RED_NOT);
+ case MINUS_ONE:
+ return CommonImages.getImage(ReviewsImages.MINUS_ONE);
+ case PLUS_ONE:
+ return CommonImages.getImage(ReviewsImages.PLUS_ONE);
+ case PLUS_TWO:
+ return CommonImages.getImage(ReviewsImages.GREEN_CHECK);
+ }
+
+ return CommonImages.getImage(CommonImages.OVERLAY_CLEAR);
+ }
+
+ private Image getVerifiedStateImage(TaskReview reviewContainer) {
+ int verifiedState = reviewContainer.getVerifiedScore();
+
+ if (verifiedState >= VERIFIED) {
+ return CommonImages.getImage(ReviewsImages.GREEN_CHECK);
+ } else if (verifiedState <= NOT_VERIFIED) {
+ return CommonImages.getImage(ReviewsImages.RED_NOT);
+ }
+
+ return CommonImages.getImage(CommonImages.OVERLAY_CLEAR);
+ }
+
+ public String getColumnText(Object element, int columnIndex) {
+ TaskReview reviewContainer = (TaskReview) element;
+
+ switch (columnIndex) {
+ case DESCRIPTION_COLUMN:
+ return reviewContainer.getSummary();
+ case INCOMING_CHANGES_COLUMN:
+ return reviewContainer.getIncomingChanges();
+ default:
+ return "";
+ }
+ }
+
+ @Override
+ public String getToolTipText(Object element) {
+ TaskReview review = (TaskReview) element;
+ StringBuilder sb = new StringBuilder();
+
+ sb.append("Description: ");
+ sb.append(review.getSummary());
+
+ sb.append(System.getProperty("line.separator"));
+ sb.append("Verified: ");
+ if (review.getVerifiedScore() >= 1) {
+ sb.append("YES");
+ } else {
+ sb.append("NO");
+ }
+
+ sb.append(System.getProperty("line.separator"));
+ sb.append("Code Review: ");
+ sb.append(review.getCodeReviewScore());
+
+ return sb.toString();
+ }
+
+ @Override
+ public void update(ViewerCell cell) {
+ Object element = cell.getElement();
+
+ int columnNumber = cell.getColumnIndex();
+
+ cell.setImage(getColumnImage(element, columnNumber));
+ cell.setText(getColumnText(element, columnNumber));
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsImages.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsImages.java
index e224e31a..fcecfac3 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsImages.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/ReviewsImages.java
@@ -59,6 +59,14 @@ public class ReviewsImages {
public static final ImageDescriptor PREVIOUS_COMMENT = create("elcl16/prevanmly_menu.png"); //$NON-NLS-1$
+ public static final ImageDescriptor PLUS_ONE = create("view16/plusOne.png"); //$NON-NLS-1$
+
+ public static final ImageDescriptor MINUS_ONE = create("view16/minusOne.png"); //$NON-NLS-1$
+
+ public static final ImageDescriptor GREEN_CHECK = create("view16/greenCheck.png"); //$NON-NLS-1$
+
+ public static final ImageDescriptor RED_NOT = create("view16/redNot.png"); //$NON-NLS-1$
+
private static ImageDescriptor create(String path) {
try {
return ImageDescriptor.createFromURL(makeIconFileURL(path));
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/Messages.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/Messages.java
index 523d4477..055eef1e 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/Messages.java
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/Messages.java
@@ -22,6 +22,20 @@ public class Messages extends NLS {
public static String AbstractCommentPart_Section_header;
+ public static String TaskEditorReviewsPart_ReviewsString;
+
+ public static String TaskEditorReviewsPart_IncomingChangesString;
+
+ public static String TaskEditorReviewsPart_VerifiedString;
+
+ public static String TaskEditorReviewsPart_CodeReviewString;
+
+ public static String TaskEditorReviewsPart_DescriptionString;
+
+ public static String TaskEditorReviewsPart_VerifiedAttribute;
+
+ public static String TaskEditorReviewsPart_CodeReviewAttribute;
+
static {
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
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
new file mode 100644
index 00000000..4ac1a827
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskEditorReviewsPart.java
@@ -0,0 +1,221 @@
+/*******************************************************************************
+ * Copyright (c) 2015, Landon Butterworth 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:
+ * Blaine Lewis & Landon Butterworth - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.reviews.ui.editors.parts;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.eclipse.jface.layout.GridDataFactory;
+import org.eclipse.jface.viewers.ArrayContentProvider;
+import org.eclipse.jface.viewers.ColumnViewerToolTipSupport;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.OpenEvent;
+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.internal.reviews.ui.ReviewColumnLabelProvider;
+import org.eclipse.mylyn.internal.reviews.ui.ReviewsUiPlugin;
+import org.eclipse.mylyn.internal.tasks.core.TaskList;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.internal.tasks.ui.editors.EditorUtil;
+import org.eclipse.mylyn.reviews.internal.core.TaskReviewsMappingsStore;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+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.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.TableColumn;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.Section;
+
+/**
+ * @author Blaine Lewis
+ * @author Landon Butterworth
+ */
+public class TaskEditorReviewsPart extends AbstractTaskEditorPart {
+
+ private static final String ID_TASK_EDITOR_REVIEWS_PART = "org.eclipse.mylyn.internal.reviews.ui.editor.parts.TaskEditorReviewsPart"; //$NON-NLS-1$
+
+ private Composite reviewsComposite;
+
+ protected Section section;
+
+ private Table reviewsTable;
+
+ private final String[] REVIEWS_COLUMNS = { Messages.TaskEditorReviewsPart_DescriptionString,
+ Messages.TaskEditorReviewsPart_CodeReviewString, Messages.TaskEditorReviewsPart_VerifiedString,
+ Messages.TaskEditorReviewsPart_IncomingChangesString };
+
+ private SelectionProviderAdapter selectionProvider;
+
+ private final int[] REVIEWS_COLUMNS_WIDTH = { 400, 50, 50, 300, 0 };
+
+ private TableViewer reviewsViewer;
+
+ private List<TaskReview> reviewContainers;
+
+ private Collection<ITask> reviews;
+
+ private final TaskReviewsMappingsStore taskReviewStore;
+
+ private final TaskList taskList = TasksUiPlugin.getTaskList();
+
+ public TaskEditorReviewsPart() {
+ taskReviewStore = ReviewsUiPlugin.getDefault().getTaskReviewsMappingStore();
+ setPartName(Messages.TaskEditorReviewsPart_ReviewsString);
+ }
+
+ @Override
+ public void createControl(Composite parent, final FormToolkit toolkit) {
+
+ if (taskReviewStore != null) {
+ Collection<String> reviewUrls = taskReviewStore.getReviewUrls(getTaskEditorPage().getTask().getUrl());
+ getReviewsFromUrls(reviewUrls);
+ }
+
+ if (reviews == null || reviews.size() == 0) {
+ //Don't build component because there are no reviews
+ return;
+ }
+
+ reviewContainers = new ArrayList<TaskReview>();
+ populateReviews(reviewContainers);
+
+ selectionProvider = new SelectionProviderAdapter();
+
+ section = createSection(parent, toolkit, true);
+ section.setText(section.getText());
+
+ createContents(toolkit, section);
+
+ setSection(toolkit, section);
+ }
+
+ private void getReviewsFromUrls(Collection<String> reviewUrls) {
+ reviews = new ArrayList<ITask>();
+
+ for (String reviewUrl : reviewUrls) {
+
+ AbstractRepositoryConnector connector = TasksUiPlugin.getRepositoryManager()
+ .getConnectorForRepositoryTaskUrl(reviewUrl);
+
+ if (connector == null) {
+ continue;
+ }
+
+ String repositoryUrl = connector.getRepositoryUrlFromTaskUrl(reviewUrl);
+
+ String reviewId = connector.getTaskIdFromTaskUrl(reviewUrl);
+
+ if (repositoryUrl == null || reviewId == null) {
+ continue;
+ }
+
+ ITask review = taskList.getTask(repositoryUrl, reviewId);
+
+ if (review != null) {
+ reviews.add(review);
+ }
+ }
+ }
+
+ private void createReviewsTable(FormToolkit toolkit, final Composite composite) {
+ reviewsTable = toolkit.createTable(reviewsComposite, SWT.MULTI | SWT.FULL_SELECTION);
+
+ reviewsTable.setLinesVisible(true);
+ reviewsTable.setHeaderVisible(true);
+ reviewsTable.setLayout(new GridLayout());
+
+ GridDataFactory.fillDefaults()
+ .align(SWT.FILL, SWT.FILL)
+ .grab(true, false)
+ .hint(500, SWT.DEFAULT)
+ .applyTo(reviewsTable);
+
+ reviewsTable.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TREE_BORDER);
+
+ for (int i = 0; i < REVIEWS_COLUMNS.length; i++) {
+ TableColumn column = new TableColumn(reviewsTable, SWT.LEFT, i);
+ column.setText(REVIEWS_COLUMNS[i]);
+ column.setWidth(REVIEWS_COLUMNS_WIDTH[i]);
+ column.setMoveable(true);
+ }
+
+ 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(getModel(), getTaskEditorPage().getAttributeEditorToolkit()));
+
+ reviewsViewer.addOpenListener(new IOpenListener() {
+ public void open(OpenEvent event) {
+ openReview(event);
+ }
+ });
+
+ reviewsViewer.setInput(reviewContainers.toArray());
+
+ getTaskEditorPage().reflow();
+ }
+
+ private void populateReviews(List<TaskReview> reviewContainers) {
+ for (ITask review : reviews) {
+ reviewContainers.add(new TaskReview(review));
+ }
+ }
+
+ private void createContents(final FormToolkit toolkit, final Section section) {
+
+ reviewsComposite = toolkit.createComposite(section);
+ section.setClient(reviewsComposite);
+ reviewsComposite.setLayout(EditorUtil.createSectionClientLayout());
+
+ getTaskEditorPage().registerDefaultDropListener(section);
+
+ createReviewsTable(toolkit, reviewsComposite);
+
+ toolkit.paintBordersFor(reviewsComposite);
+ }
+
+ public boolean isReviewsSectionExpanded() {
+ return section != null && section.isExpanded();
+ }
+
+ protected void openReview(OpenEvent event) {
+ List<TaskReview> reviewsToOpen = new ArrayList<TaskReview>();
+
+ StructuredSelection selection = (StructuredSelection) event.getSelection();
+
+ List<?> items = selection.toList();
+ for (Object item : items) {
+ if (item instanceof TaskReview) {
+ reviewsToOpen.add((TaskReview) item);
+ }
+ }
+
+ if (reviewsToOpen.isEmpty()) {
+ return;
+ }
+
+ for (TaskReview openThis : reviewsToOpen) {
+ TasksUiUtil.openTask(openThis.getUrl());
+ }
+ }
+}
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskReview.java b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskReview.java
new file mode 100644
index 00000000..87c917b1
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/TaskReview.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Landon Butterworth 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:
+ * Landon Butterworth - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.reviews.ui.editors.parts;
+
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState;
+
+public class TaskReview {
+
+ private final ITask review;
+
+ public TaskReview(ITask review) {
+ this.review = review;
+ }
+
+ public String getSummary() {
+ return review.getSummary();
+ }
+
+ public int getCodeReviewScore() {
+ String reviewScore = review.getAttribute(Messages.TaskEditorReviewsPart_CodeReviewAttribute);
+
+ try {
+ return Integer.parseInt(reviewScore);
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
+ public int getVerifiedScore() {
+ String verifiedScore = review.getAttribute(Messages.TaskEditorReviewsPart_VerifiedAttribute);
+
+ try {
+ return Integer.parseInt(verifiedScore);
+ } catch (NumberFormatException e) {
+ return 0;
+ }
+ }
+
+ public String getIncomingChanges() {
+ return review.getAttribute("INCOMING_REVIEW");
+ }
+
+ public String getUrl() {
+ return review.getUrl();
+ }
+
+ public SynchronizationState getSyncState() {
+ return review.getSynchronizationState();
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/messages.properties b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/messages.properties
index 1a5d18c4..661bdc34 100644
--- a/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/messages.properties
+++ b/org.eclipse.mylyn.reviews.ui/src/org/eclipse/mylyn/internal/reviews/ui/editors/parts/messages.properties
@@ -7,7 +7,15 @@
#
# Contributors:
# Tasktop Technologies - initial API and implementation
+# Landon Butterworth
###############################################################################
AbstractCommentPart_Draft=DRAFT
AbstractCommentPart_No_author=(no author)
AbstractCommentPart_Section_header={0} {1}
+TaskEditorReviewsPart_ReviewsString=Reviews
+TaskEditorReviewsPart_IncomingChangesString=Incoming Changes
+TaskEditorReviewsPart_VerifiedString=V
+TaskEditorReviewsPart_CodeReviewString=CR
+TaskEditorReviewsPart_DescriptionString=Description
+TaskEditorReviewsPart_VerifiedAttribute=VERIFIED
+TaskEditorReviewsPart_CodeReviewAttribute=CODE_REVIEW

Back to the top