Skip to content

Commit

Permalink
Refactor: Move ellipsis logic to specific columns to avoid shared com…
Browse files Browse the repository at this point in the history
…ponent issues
  • Loading branch information
AnickaG committed Nov 29, 2024
1 parent 96a3ce3 commit 1f4f813
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javafx.scene.control.ContextMenu;
import javafx.scene.control.Control;
import javafx.scene.control.Label;
import javafx.scene.control.OverrunStyle;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.control.SelectionMode;
import javafx.scene.control.TableColumn;
Expand All @@ -27,6 +28,7 @@
import javafx.scene.control.TitledPane;
import javafx.scene.control.TreeItem;
import javafx.scene.layout.VBox;
import javafx.stage.Screen;

import org.jabref.gui.DialogService;
import org.jabref.gui.StateManager;
Expand Down Expand Up @@ -207,12 +209,14 @@ private void initUnlinkedFilesList() {
private void initResultTable() {
colFile.setCellValueFactory(cellData -> cellData.getValue().file());
new ValueTableCellFactory<ImportFilesResultItemViewModel, String>()
.withText(item -> item).withTooltip(item -> item)
.withGraphic(this::createEllipsisLabel)
.withTooltip(item -> item)
.install(colFile);

colMessage.setCellValueFactory(cellData -> cellData.getValue().message());
new ValueTableCellFactory<ImportFilesResultItemViewModel, String>()
.withText(item -> item).withTooltip(item -> item)
.withGraphic(this::createEllipsisLabel)
.withTooltip(item -> item)
.install(colMessage);

colStatus.setCellValueFactory(cellData -> cellData.getValue().icon());
Expand Down Expand Up @@ -273,6 +277,18 @@ void exportSelected() {
viewModel.startExport();
}

/**
* Creates a Label with a maximum width and ellipsis for overflow.
* Truncates text if it exceeds two-thirds of the screen width.
*/
private Label createEllipsisLabel(String text) {
Label label = new Label(text);
double maxWidth = Screen.getPrimary().getBounds().getWidth() * 2 / 3;
label.setMaxWidth(maxWidth);
label.setTextOverrun(OverrunStyle.LEADING_ELLIPSIS);
return label;
}

/**
* Expands or collapses the specified tree according to the <code>expand</code>-parameter.
*/
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/org/jabref/gui/util/ValueTableCellFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import javafx.event.EventHandler;
import javafx.scene.Node;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.OverrunStyle;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.Tooltip;
Expand Down Expand Up @@ -123,7 +122,6 @@ protected void updateItem(T item, boolean empty) {
if (StringUtil.isNotBlank(tooltipText)) {
Screen currentScreen = Screen.getPrimary();
double maxWidth = currentScreen.getBounds().getWidth();
setTextOverrun(OverrunStyle.LEADING_ELLIPSIS);
Tooltip tooltip = new Tooltip(tooltipText);
tooltip.setMaxWidth(maxWidth * 2 / 3);
tooltip.setWrapText(true);
Expand Down

0 comments on commit 1f4f813

Please sign in to comment.