Skip to content

Commit

Permalink
Merge pull request #85 from Luro02/main
Browse files Browse the repository at this point in the history
Fix several display bugs
  • Loading branch information
Luro02 authored Dec 13, 2024
2 parents c33164d + 36bd670 commit cde355a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import com.intellij.DynamicBundle;
import edu.kit.kastel.sdq.artemis4j.grading.Annotation;
import org.jetbrains.annotations.NotNull;

/**
* The table model for the annotations table.
Expand Down Expand Up @@ -58,8 +59,11 @@ public Object getValueAt(int row, int column) {
.getMistakeType()
.getButtonText()
.translateTo(LOCALE);
case LINES_COLUMN -> formatLines(annotation);
case FILE_COLUMN -> annotation.getFilePath();
case LINES_COLUMN -> LineLocation.fromAnnotation(annotation);
case FILE_COLUMN -> annotation
.getFilePath()
// for display purposes, replace backslashes with forward slashes
.replace("\\", "/");
case SOURCE_COLUMN -> annotation.getSource();
case CUSTOM_MESSAGE_COLUMN -> annotation.getCustomMessage().orElse("");
case CUSTOM_PENALTY_COLUMN -> annotation
Expand All @@ -85,14 +89,39 @@ public Annotation get(int index) {
return annotations.get(index);
}

private String formatLines(Annotation annotation) {
int startLine = annotation.getStartLine() + 1;
int endLine = annotation.getEndLine() + 1;

if (startLine == endLine) {
return String.valueOf(startLine);
@Override
public Class<?> getColumnClass(int columnIndex) {
// This must be overridden, otherwise LineLocation#compareTo will not be called.
if (columnIndex == LINES_COLUMN) {
return LineLocation.class;
} else {
return String.format("%d - %d", startLine, endLine);
return Object.class;
}
}

public record LineLocation(int startLine, int endLine) implements Comparable<LineLocation> {
public static LineLocation fromAnnotation(Annotation annotation) {
return new LineLocation(annotation.getStartLine() + 1, annotation.getEndLine() + 1);
}

@Override
public String toString() {
return startLine == endLine ? "%d".formatted(startLine) : "%d - %s".formatted(startLine, endLine);
}

@Override
public int compareTo(@NotNull LineLocation other) {
// It is not necessary to override equals and hashCode, because
// this is already done by the record keyword.
if (this.equals(other)) {
return 0;
}

if (startLine != other.startLine) {
return Integer.compare(startLine, other.startLine);
}

return Integer.compare(endLine, other.endLine);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package edu.kit.kastel.sdq.intelligrade.extensions.guis;

import java.awt.event.ItemEvent;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;

Expand Down Expand Up @@ -245,13 +246,13 @@ private void handleExamSelected(ItemEvent e) {
var item = (OptionalExam) e.getItem();
if (item.exam() != null) {
for (var group : item.exam().getExerciseGroups()) {
for (var exercise : group.getProgrammingExercises()) {
for (var exercise : sortExercises(group.getProgrammingExercises())) {
exerciseSelector.addItem(exercise);
}
}
} else {
for (ProgrammingExercise programmingExercise :
courseSelector.getItem().getProgrammingExercises()) {
sortExercises(courseSelector.getItem().getProgrammingExercises())) {
exerciseSelector.addItem(programmingExercise);
}
}
Expand All @@ -263,6 +264,14 @@ private void handleExamSelected(ItemEvent e) {
updateUI();
}

private static <T extends ProgrammingExercise> List<T> sortExercises(List<T> exercises) {
List<T> result = new ArrayList<>(exercises);

result.sort((a, b) -> CharSequence.compare(a.getTitle(), b.getTitle()));

return result;
}

private void handleCourseSelected(ItemEvent e) {
// Course was selected: Update the exam selector with the exams of the course
// This triggers an item event in the exam selector, which updates the exercise selector
Expand Down

0 comments on commit cde355a

Please sign in to comment.