Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rating in main table #9023

Merged
merged 9 commits into from
Aug 4, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve

### Fixed

- We fixed an issue where the user could not rate an entry in the main table when an entry was not yet ranked. [#5842](https://github.com/JabRef/jabref/issues/5842)
- We fixed an issue that caused JabRef to sometimes open multiple instances when "Remote Operation" is enabled. [#8653](https://github.com/JabRef/jabref/issues/8653)
- We fixed an issue where linked files with the filetype "application/pdf" in an entry were not shown with the correct PDF-Icon in the main table [8930](https://github.com/JabRef/jabref/issues/8930)
- We fixed an issue where "open folder" for linked files did not open the folder and did not select the file unter certain Linux desktop environments [#8679](https://github.com/JabRef/jabref/issues/8679), [#8849](https://github.com/JabRef/jabref/issues/8849)
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/org/jabref/gui/Base.css
Original file line number Diff line number Diff line change
Expand Up @@ -1305,3 +1305,16 @@ TextFlow * {
.text-field:invalid {
-fx-background-color: rgba(240, 128, 128, 0.5);
}

.rating {
-fx-skin: "org.jabref.gui.util.CustomRatingSkin";
-fx-padding: 0.5em 0px 0px 0px;
}

.rating > .container > .button {
-fx-icon-color: derive(-fx-text-base-color, 85%);
}

.rating > .container > .button.strong {
-fx-icon-color: -fx-text-base-color;
}
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/gui/Dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -132,3 +132,11 @@
.notification-bar > .pane {
-fx-background-color: -fx-light-text-color;
}

.rating > .container > .button {
-fx-icon-color: derive(-fx-light-text-color, -50%);
}

.rating > .container > .button.strong {
-fx-icon-color: -fx-light-text-color;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import javafx.scene.control.MenuItem;
import javafx.scene.control.Tooltip;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;

import org.jabref.gui.icon.JabRefIcon;
import org.jabref.gui.maintable.BibEntryTableViewModel;
Expand Down Expand Up @@ -55,7 +56,7 @@ public SpecialFieldColumn(MainTableColumnModel model, PreferencesService prefere
MainTableColumnFactory.setExactWidth(this, SpecialFieldsPreferences.COLUMN_RANKING_WIDTH);
this.setResizable(false);
new OptionalValueTableCellFactory<BibEntryTableViewModel, SpecialFieldValueViewModel>()
.withGraphicIfPresent(this::createSpecialRating)
.withGraphic(this::createSpecialRating)
.install(this);
} else {
MainTableColumnFactory.setExactWidth(this, ColumnPreferences.ICON_COLUMN_WIDTH);
Expand Down Expand Up @@ -89,9 +90,24 @@ public SpecialFieldColumn(MainTableColumnModel model, PreferencesService prefere
this.setSortable(true);
}

private Rating createSpecialRating(BibEntryTableViewModel entry, SpecialFieldValueViewModel value) {
private Rating createSpecialRating(BibEntryTableViewModel entry, Optional<SpecialFieldValueViewModel> value) {
Rating ranking = new Rating();
ranking.setRating(value.getValue().toRating());

if (value.isPresent()) {
ranking.setRating(value.get().getValue().toRating());
} else {
ranking.setRating(0);
}

ranking.addEventFilter(MouseEvent.MOUSE_CLICKED, event -> {
if (event.getButton().equals(MouseButton.PRIMARY) && event.getClickCount() == 2) {
ranking.setRating(0);
event.consume();
} else if (event.getButton().equals(MouseButton.SECONDARY)) {
event.consume();
}
});

EasyBind.subscribe(ranking.ratingProperty(), rating ->
new SpecialFieldViewModel(SpecialField.RANKING, preferencesService, undoManager)
.setSpecialFieldValue(entry.getEntry(), SpecialFieldValue.getRating(rating.intValue())));
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/org/jabref/gui/util/CustomRatingSkin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.jabref.gui.util;

import javafx.scene.Node;

import org.jabref.gui.icon.IconTheme;

import impl.org.controlsfx.skin.RatingSkin;
import org.controlsfx.control.Rating;

public class CustomRatingSkin extends RatingSkin {
public CustomRatingSkin(Rating control) {
super(control);

consumeMouseEvents(false);
}

@Override
protected Node createButtonNode() {
return IconTheme.JabRefIcons.RANKING.getGraphicNode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public enum SpecialFieldValue {

public static SpecialFieldValue getRating(int ranking) {
return switch (ranking) {
case 0 -> CLEAR_RANK;
case 1 -> RANK_1;
case 2 -> RANK_2;
case 3 -> RANK_3;
Expand All @@ -58,6 +59,7 @@ public Optional<String> getFieldValue() {

public int toRating() {
return switch (this) {
case CLEAR_RANK -> 0;
case RANK_1 -> 1;
case RANK_2 -> 2;
case RANK_3 -> 3;
Expand Down