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

Convert Strings Dialog to javafx #3735

Merged
merged 38 commits into from
Feb 17, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
cf7a48f
Convert String dialog to javafx
Siedlerchr Feb 17, 2018
5b15f26
add save and cancel buttons
Siedlerchr Feb 17, 2018
017ac37
add method for saving
Siedlerchr Feb 18, 2018
0d40b60
Merge branch 'maintable-beta' into editStringsjavafx
Siedlerchr Feb 22, 2018
4482a7a
Merge branch 'maintable-beta' into editStringsjavafx
Siedlerchr Feb 25, 2018
4ed242b
First attempt at validation
Siedlerchr Feb 25, 2018
e764d04
use mvvmfx validation
Siedlerchr Feb 25, 2018
f5e2a27
Add validation in factory
Siedlerchr Feb 26, 2018
f1e4cd8
Merge remote-tracking branch 'upstream/maintable-beta' into editStrin…
Siedlerchr Feb 27, 2018
aacd4f9
remove old comment
Siedlerchr Feb 27, 2018
ed77f62
add css but still does not work :(
Siedlerchr Feb 27, 2018
5d0755c
Merge remote-tracking branch 'upstream/maintable-beta' into editStrin…
Siedlerchr Apr 1, 2018
424d463
convert to new javafx view/controller
Siedlerchr Apr 1, 2018
dd63df4
Merge remote-tracking branch 'upstream/maintable-beta' into editStrin…
Siedlerchr Apr 3, 2018
84c0aba
play around with validation
Siedlerchr Apr 3, 2018
3fa8648
Merge remote-tracking branch 'upstream/master' into editStringsjavafx
Siedlerchr Jan 20, 2019
2482bd0
refactor
Siedlerchr Jan 20, 2019
db5debd
fix l10n
Siedlerchr Jan 20, 2019
ca2dc2c
Merge remote-tracking branch 'upstream/master' into editStringsjavafx
Siedlerchr Jan 21, 2019
4101f76
fix loading of string dialog
Siedlerchr Jan 21, 2019
014dd12
fix imports
Siedlerchr Jan 21, 2019
c273ecb
Merge remote-tracking branch 'upstream/master' into editStringsjavafx
Siedlerchr Feb 1, 2019
f763eaf
remove old stuff
Siedlerchr Feb 1, 2019
d973630
fix Validation
Siedlerchr Feb 2, 2019
72bd1ad
fix codacy, improve layout
Siedlerchr Feb 2, 2019
23be3e3
Refactorings and renamings
Siedlerchr Feb 3, 2019
74db19a
first part for factory
Siedlerchr Feb 3, 2019
2f15c24
Merge remote-tracking branch 'upstream/master' into editStringsjavafx
Siedlerchr Feb 4, 2019
30d5bf1
fix visibilty error
Siedlerchr Feb 4, 2019
634bed4
Merge remote-tracking branch 'upstream/master' into editStringsjavafx
Siedlerchr Feb 15, 2019
2363c15
move validation textfieldtablecell to factory
Siedlerchr Feb 15, 2019
1c2ffa3
fix import order
Siedlerchr Feb 15, 2019
49dfd2f
fix merge erros in l10n
Siedlerchr Feb 15, 2019
8ed811b
remove obsolete key from l10n
Siedlerchr Feb 15, 2019
018a432
remove unused TextField
Siedlerchr Feb 16, 2019
f5a399f
renamings and remove uncessary methods
Siedlerchr Feb 16, 2019
616cbeb
extract string adding to bibdatabase
Siedlerchr Feb 17, 2019
0082b13
fix checkstyle
Siedlerchr Feb 17, 2019
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
53 changes: 46 additions & 7 deletions src/main/java/org/jabref/gui/strings/StringDialogController.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.scene.control.Button;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableColumn.CellEditEvent;
import javafx.scene.control.TableView;
import javafx.scene.control.Tooltip;
import javafx.scene.control.cell.TextFieldTableCell;
import javafx.util.Callback;
import javafx.util.converter.DefaultStringConverter;

import org.jabref.gui.AbstractController;
import org.jabref.gui.IconTheme.JabRefIcons;
import org.jabref.gui.StateManager;
import org.jabref.gui.help.HelpAction;
import org.jabref.logic.help.HelpFile;
import org.jabref.logic.l10n.Localization;
import org.jabref.gui.StateManager;

import org.controlsfx.tools.ValueExtractor;
import org.controlsfx.validation.ValidationSupport;
import org.controlsfx.validation.Validator;

public class StringDialogController extends AbstractController<StringDialogViewModel> {

Expand Down Expand Up @@ -46,17 +53,49 @@ private void initialize() {
colLabel.setCellValueFactory(cellData -> cellData.getValue().getLabel());
colContent.setCellValueFactory(cellData -> cellData.getValue().getContent());

colLabel.setCellFactory(TextFieldTableCell.<StringViewModel> forTableColumn());
colContent.setCellFactory(TextFieldTableCell.<StringViewModel> forTableColumn());
ValidationSupport validationSupport = new ValidationSupport();

//Register TextfieldTableCell Control for validation
ValueExtractor.addObservableValueExtractor(c -> c instanceof TextFieldTableCell, c -> ((TextFieldTableCell<?, String>) c).textProperty());

colLabel.setCellFactory(new Callback<TableColumn<StringViewModel, String>, TableCell<StringViewModel, String>>() {

@Override
public TableCell<StringViewModel, String> call(TableColumn<StringViewModel, String> param) {

TextFieldTableCell<StringViewModel, String> cell = new TextFieldTableCell<>(new DefaultStringConverter());
validationSupport.registerValidator(cell, Validator.createEmptyValidator("Text is required"));
return cell;
}

});

colContent.setCellFactory(new Callback<TableColumn<StringViewModel, String>, TableCell<StringViewModel, String>>() {

@Override
public TableCell<StringViewModel, String> call(TableColumn<StringViewModel, String> param) {

TextFieldTableCell<StringViewModel, String> cell = new TextFieldTableCell<>(new DefaultStringConverter());
validationSupport.registerValidator(cell, Validator.createEmptyValidator("Text is required"));
return cell;
}
});

colLabel.setOnEditCommit(
(CellEditEvent<StringViewModel, String> t) -> {
t.getTableView().getItems().get(
t.getTablePosition().getRow()).setLabel(t.getNewValue());
t.getTableView()
.getItems()
.get(
t.getTablePosition().getRow())
Copy link
Member

Choose a reason for hiding this comment

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

t.getRowValue is easier (and please rename t to something more descriptive.

.setLabel(t.getNewValue());
});
colContent.setOnEditCommit(
(CellEditEvent<StringViewModel, String> t) -> {
t.getTableView().getItems().get(
t.getTablePosition().getRow()).setContent(t.getNewValue());
t.getTableView()
.getItems()
.get(
t.getTablePosition().getRow())
.setContent(t.getNewValue());
});

tblStrings.itemsProperty().bindBidirectional(viewModel.allStringsProperty());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ public StringDialogViewModel(StateManager stateManager) {

private void addAllStringsFromDB() {

Copy link
Member

Choose a reason for hiding this comment

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

remove empty line

Set<StringViewModel> strings = db.getStringKeySet().stream()
Set<StringViewModel> strings = db.getStringKeySet()
.stream()
.map(string -> db.getString(string))
.sorted(new BibtexStringComparator(false))
.map(this::convertFromBibTexString).collect(Collectors.toSet());
.map(this::convertFromBibTexString)
.collect(Collectors.toSet());
allStrings.addAll(strings);
}

Expand Down