Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Feature edit annotation messages #170

Merged
merged 8 commits into from
Apr 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package edu.kit.kastel.sdq.eclipse.grading.api.controller;

import java.util.List;
import java.util.Optional;

import edu.kit.kastel.sdq.eclipse.grading.api.artemis.IProjectFileNamingStrategy;
import edu.kit.kastel.sdq.eclipse.grading.api.artemis.mapping.ICourse;
Expand Down Expand Up @@ -67,6 +68,8 @@ void addAnnotation(String annotationUUID, IMistakeType mistakeType, int startLin
*/
List<IAnnotation> getAnnotations();

Optional<IAnnotation> getAnnotationByUUID(String uuid);

/**
*
* @param className
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ public List<IAnnotation> getAnnotations() {
return this.annotationDao.getAnnotations().stream().collect(Collectors.toUnmodifiableList());
}

@Override
public Optional<IAnnotation> getAnnotationByUUID(String uuid) {
return this.annotationDao.getAnnotations().stream().filter(annotation -> annotation.getUUID().equals(uuid)).findFirst();
}

@Override
public List<IAnnotation> getAnnotations(String className) {
return this.annotationDao.getAnnotations().stream().filter(annotation -> annotation.getClassFilePath().equals(className))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Bundle-ActivationPolicy: lazy
Bundle-Activator: edu.kit.kastel.eclipse.common.view.activator.Activator
Automatic-Module-Name: edu.kit.kastel.sdq.eclipse.common
Export-Package: edu.kit.kastel.eclipse.common.view.controllers,
edu.kit.kastel.eclipse.common.view.marker,
edu.kit.kastel.eclipse.common.view.utilities
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* Licensed under EPL-2.0 2022. */
package edu.kit.kastel.eclipse.common.view.marker;

import java.lang.reflect.Field;

import org.eclipse.core.runtime.ILog;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.ui.internal.views.markers.ExtendedMarkersView;
import org.eclipse.ui.internal.views.markers.MarkersTreeViewer;
import org.eclipse.ui.views.markers.MarkerSupportView;

import edu.kit.kastel.eclipse.common.view.utilities.AssessmentUtilities;
Expand All @@ -13,8 +20,21 @@
*/
public class AssessmentMarkerView extends MarkerSupportView {

private static final ILog log = Platform.getLog(AssessmentMarkerView.class);

public AssessmentMarkerView() {
super(AssessmentUtilities.MARKER_VIEW_ID);
}

public void addDoubleClickListener(IDoubleClickListener doubleClickListener) {
try {
Field viewerField = ExtendedMarkersView.class.getDeclaredField("viewer");
viewerField.setAccessible(true);
MarkersTreeViewer viewer = (MarkersTreeViewer) viewerField.get(this);
viewer.addDoubleClickListener(doubleClickListener);
} catch (NoSuchFieldException | IllegalAccessException e) {
log.error("Could not attach DoubleClickListener to AssessmentMarkerView", e);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

import edu.kit.kastel.eclipse.common.view.marker.AssessmentMarkerView;
import edu.kit.kastel.eclipse.common.view.utilities.AssessmentUtilities;
import edu.kit.kastel.eclipse.grading.view.activator.Activator;
import edu.kit.kastel.eclipse.grading.view.controllers.AssessmentViewController;
import edu.kit.kastel.eclipse.grading.view.listeners.AssessmentMarkerViewDoubleClickListener;
import edu.kit.kastel.eclipse.grading.view.listeners.KeyboardAwareMouseListener;
import edu.kit.kastel.sdq.eclipse.grading.api.artemis.mapping.SubmissionFilter;
import edu.kit.kastel.sdq.eclipse.grading.api.backendstate.Transition;
Expand Down Expand Up @@ -61,6 +65,7 @@ public ArtemisGradingView() {
this.mistakeButtons = new HashMap<>();
this.possibleActions = new EnumMap<>(Transition.class);
this.initializePossibleActions();
this.initializeAnnotationEditing();
this.addListenerForMarkerDeletion();
}

Expand All @@ -82,6 +87,13 @@ private void addListenerForMarkerDeletion() {
}));
}

private void initializeAnnotationEditing() {
IViewPart view = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(AssessmentMarkerView.class.getName());
if (view instanceof AssessmentMarkerView markerView) {
markerView.addDoubleClickListener(new AssessmentMarkerViewDoubleClickListener(this));
}
}

private void addSelectionListenerForLoadFromBacklogButton(Button btnLoadAgain) {
btnLoadAgain.addListener(SWT.Selection, e -> {
this.viewController.onLoadAgain();
Expand Down Expand Up @@ -474,7 +486,7 @@ private void updateMistakeButtonToolTips(IMistakeType mistakeType) {
}
}

private void updatePenalties() {
public void updatePenalties() {
this.viewController.getRatingGroups().forEach(ratingGroup -> this.updatePenalty(ratingGroup.getDisplayName()));
this.updateAllToolTips();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Licensed under EPL-2.0 2022. */
package edu.kit.kastel.eclipse.grading.view.assessment;

import java.util.Objects;

import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
Expand Down Expand Up @@ -30,14 +32,18 @@ public class CustomButtonDialog extends Dialog {
private static final int CUSTOM_PENALTY_FIELD_WIDTH_MULTIPLIER = 24;
private static final int CUSTOM_PENALTY_FIELD_HEIGHT_MULTIPLIER = 8;

// Internal state
private Text customMessageInputField;
private Spinner customPenaltyInputField;
private boolean closedByOk;
private boolean forcePenaltyField;
private final AssessmentViewController viewController;

// Data
private String customMessage;
private Double customPenalty;
private IMistakeType customMistake;
private final AssessmentViewController viewController;
private final String ratingGroupName;
private boolean closedByOk;

public CustomButtonDialog(Shell parentShell, AssessmentViewController viewController, String ratingGroupName, IMistakeType mistake) {
super(parentShell);
Expand Down Expand Up @@ -92,22 +98,46 @@ protected Control createDialogArea(Composite parent) {
}

this.customMessageInputField.setLayoutData(customMessageInputFieldData);
if (this.customMistake != null) { // Don't display the spinner if points are determined internally.
this.customMessageInputField.setText(Objects.requireNonNullElse(this.customMessage, ""));
if (this.customMistake != null || this.forcePenaltyField) { // Don't display the spinner if points are
// determined internally.
final Label customPenaltyLabel = new Label(comp, SWT.RIGHT);
customPenaltyLabel.setText("Custom Penalty: ");
this.customPenaltyInputField = new Spinner(comp, SWT.SINGLE | SWT.BORDER);
this.customPenaltyInputField.setDigits(1);
this.customPenaltyInputField.setIncrement(5);
this.customPenaltyInputField.setLayoutData(data);

// Multiply by 10 because the selection internally stores the selection as an
// integer ignoring the decimal point. (0.5 ==> 5, 1 ==> 10)
this.customPenaltyInputField.setSelection((int) (Objects.requireNonNullElse(customPenalty, 0d).doubleValue() * 10));
}

return comp;
}

public void setForcePenaltyField(boolean forcePenaltyField) {
this.forcePenaltyField = forcePenaltyField;
}

public void setCustomMessage(String customMessage) {
this.customMessage = customMessage;
if (this.customMessageInputField != null) {
this.customMessageInputField.setText(this.customMessage);
}
}

public String getCustomMessage() {
return this.customMessage;
}

public void setCustomPenalty(Double customPenalty) {
this.customPenalty = customPenalty;
if (this.customPenaltyInputField != null) {
this.customPenaltyInputField.setSelection((int) (customPenalty * 10));
}
}

public Double getCustomPenalty() {
return this.customPenalty;
}
Expand All @@ -116,9 +146,11 @@ public Double getCustomPenalty() {
protected void okPressed() {
this.closedByOk = true;
this.customMessage = this.customMessageInputField.getText();
if (this.customMistake != null) { // don't create an annotation iff the annotation is generated externally.
if (this.customPenaltyInputField != null) {
this.customPenalty = Double.parseDouble(this.customPenaltyInputField.getText().replace(',', '.'));
this.viewController.addAssessmentAnnotation(this.customMistake, this.customMessage, this.customPenalty, this.ratingGroupName);
if (this.customMistake != null) { // don't create an annotation iff the annotation is generated externally.
this.viewController.addAssessmentAnnotation(this.customMistake, this.customMessage, this.customPenalty, this.ratingGroupName);
}
}
super.okPressed();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/* Licensed under EPL-2.0 2022. */
package edu.kit.kastel.eclipse.grading.view.listeners;

import java.util.NoSuchElementException;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.TreeSelection;
import org.eclipse.ui.views.markers.MarkerItem;

import edu.kit.kastel.eclipse.common.view.utilities.AssessmentUtilities;
import edu.kit.kastel.eclipse.grading.view.activator.Activator;
import edu.kit.kastel.eclipse.grading.view.assessment.ArtemisGradingView;
import edu.kit.kastel.eclipse.grading.view.assessment.CustomButtonDialog;
import edu.kit.kastel.sdq.eclipse.grading.api.model.IAnnotation;

public class AssessmentMarkerViewDoubleClickListener implements IDoubleClickListener {

private ArtemisGradingView gradingView;

public AssessmentMarkerViewDoubleClickListener(ArtemisGradingView gradingView) {
this.gradingView = gradingView;
}

@Override
public void doubleClick(DoubleClickEvent event) {
if (event.getSelection().isEmpty()) {
// No element clicked
return;
}

// instanceof is required... :(
if (event.getSelection()instanceof TreeSelection selection) {
if (selection.getFirstElement()instanceof MarkerItem item) {
Comment on lines +34 to +35
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll change our formatter here .. :D

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind .. it's a bug :( diffplug/spotless#1046

try {
IAnnotation annotation = Activator.getDefault().getSystemwideController().getCurrentAssessmentController()
.getAnnotationByUUID(item.getMarker().getAttribute(AssessmentUtilities.MARKER_ATTRIBUTE_ANNOTATION_ID).toString())
.orElseThrow(() -> new NoSuchElementException("Could not find annotation. Please create it again."));

String customMessage = annotation.getCustomMessage().orElse("");

CustomButtonDialog dialog = new CustomButtonDialog(AssessmentUtilities.getWindowsShell(), null, null, null);

if (annotation.getMistakeType().isCustomPenalty()) {
dialog.setCustomPenalty(annotation.getCustomPenalty().orElse(0d));
dialog.setForcePenaltyField(true);
}

dialog.setCustomMessage(customMessage);
dialog.setBlockOnOpen(true);
dialog.open();

String newMessage = dialog.getCustomMessage();
Double newPenalty = annotation.getMistakeType().isCustomPenalty() ? dialog.getCustomPenalty() : annotation.getCustomPenalty().orElse(0d);

item.getMarker().setAttribute(AssessmentUtilities.MARKER_ATTRIBUTE_CUSTOM_MESSAGE, newMessage);
item.getMarker().setAttribute(AssessmentUtilities.MARKER_ATTRIBUTE_CUSTOM_PENALTY, newPenalty.toString());

Activator.getDefault().getSystemwideController().getCurrentAssessmentController().modifyAnnotation(annotation.getUUID(), newMessage,
newPenalty);
this.gradingView.updatePenalties();
} catch (CoreException e) {
e.printStackTrace();
}
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

import edu.kit.kastel.eclipse.common.view.marker.AssessmentMarkerView;
import edu.kit.kastel.eclipse.grading.view.assessment.ArtemisGradingView;

public class Perspective implements IPerspectiveFactory {

@Override
Expand All @@ -15,13 +18,13 @@ public void createInitialLayout(IPageLayout layout) {
left.addView(IPageLayout.ID_PROJECT_EXPLORER);

IFolderLayout rightUp = layout.createFolder("rightUp", IPageLayout.RIGHT, 0.7F, editorArea);
rightUp.addView("edu.kit.kastel.eclipse.grading.view.assessment.ArtemisGradingView");
rightUp.addView(ArtemisGradingView.class.getName());

IFolderLayout rightDown = layout.createFolder("rightDown", IPageLayout.BOTTOM, 0.7F, "rightUp");
rightDown.addView(IPageLayout.ID_OUTLINE);

IFolderLayout bottom = layout.createFolder("bottom", IPageLayout.BOTTOM, 0.6F, editorArea);
bottom.addView("edu.kit.kastel.eclipse.common.view.marker.AssessmentMarkerView");
bottom.addView(AssessmentMarkerView.class.getName());
bottom.addView(IPageLayout.ID_PROBLEM_VIEW);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;

import edu.kit.kastel.eclipse.common.view.marker.AssessmentMarkerView;
import edu.kit.kastel.eclipse.student.view.ui.ArtemisStudentView;

public class Perspective implements IPerspectiveFactory {

@Override
Expand All @@ -15,13 +18,13 @@ public void createInitialLayout(IPageLayout layout) {
left.addView(IPageLayout.ID_PROJECT_EXPLORER);

IFolderLayout rightUp = layout.createFolder("rightUp", IPageLayout.RIGHT, 0.7F, editorArea);
rightUp.addView("edu.kit.kastel.eclipse.student.view.ui.ArtemisStudentView");
rightUp.addView(ArtemisStudentView.class.getName());

IFolderLayout rightDown = layout.createFolder("rightDown", IPageLayout.BOTTOM, 0.7F, "rightUp");
rightDown.addView(IPageLayout.ID_OUTLINE);

IFolderLayout bottom = layout.createFolder("bottom", IPageLayout.BOTTOM, 0.6F, editorArea);
bottom.addView("edu.kit.kastel.eclipse.common.view.marker.AssessmentMarkerView");
bottom.addView(AssessmentMarkerView.class.getName());
bottom.addView(IPageLayout.ID_PROBLEM_VIEW);
}
}
Loading