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

improve unlinked files dialog #12195

Merged
merged 9 commits into from
Dec 2, 2024
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
Loading