Skip to content

Commit

Permalink
Renaming, use properties in controller
Browse files Browse the repository at this point in the history
open dialog with attach file action
  • Loading branch information
Siedlerchr committed Aug 6, 2017
1 parent 8dca324 commit dfde523
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 16 deletions.
17 changes: 9 additions & 8 deletions src/main/java/org/jabref/gui/filelist/AttachFileAction.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package org.jabref.gui.filelist;

import java.util.Optional;
import javafx.application.Platform;

import org.jabref.gui.BasePanel;
import org.jabref.gui.actions.BaseAction;
import org.jabref.gui.undo.UndoableFieldChange;
import org.jabref.logic.l10n.Localization;
import org.jabref.model.FieldChange;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.LinkedFile;

public class AttachFileAction implements BaseAction {

private final BasePanel panel;


public AttachFileAction(BasePanel panel) {
this.panel = panel;
}
Expand All @@ -28,18 +24,23 @@ public void action() {
}
BibEntry entry = panel.getSelectedEntries().get(0);
LinkedFile flEntry = new LinkedFile("", "", "");
FileListEntryEditor editor = new FileListEntryEditor(flEntry, false, true,

FileListDialogView dlg = new FileListDialogView();

Platform.runLater(() -> dlg.show());
/* FileListEntryEditor editor = new FileListEntryEditor(flEntry, false, true,
panel.getBibDatabaseContext());
editor.setVisible(true, true);
if (editor.okPressed()) {
Optional<FieldChange> fieldChange = entry.addFile(flEntry);

if (fieldChange.isPresent()) {
UndoableFieldChange ce = new UndoableFieldChange(entry, FieldName.FILE,
entry.getField(FieldName.FILE).orElse(null), fieldChange.get().getNewValue());
panel.getUndoManager().addEdit(ce);
panel.markBaseChanged();
}
}
}*/
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,21 @@ public class FileListDialogController extends AbstractController<FileListDialogV
@FXML
private void initialize() {
viewModel = new FileListDialogViewModel();
setBindings();
}

private void setBindings() {

cmbFileType.itemsProperty().bindBidirectional(viewModel.externalFileTypeProperty());
tfDescription.textProperty().bindBidirectional(viewModel.descriptionProperty());
tfLink.textProperty().bindBidirectional(viewModel.linkProperty());
}

@FXML
void browseFileDialog(ActionEvent event) {
String fileText = tfLink.getText().trim();

String fileText = viewModel.linkProperty().get();

Optional<Path> file = FileHelper.expandFilename(stateManager.getActiveDatabase().get(), fileText,
Globals.prefs.getFileDirectoryPreferences());

Expand All @@ -73,7 +83,7 @@ void browseFileDialog(ActionEvent event) {
.getFileDirectoriesAsPaths(Globals.prefs.getFileDirectoryPreferences());
newFile = FileUtil.shortenFileName(newFile, fileDirectories);

tfLink.setText(newFile.toString());
viewModel.linkProperty().set(newFile.toString());
tfLink.requestFocus();
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,30 @@

import org.jabref.gui.AbstractViewModel;
import org.jabref.gui.externalfiletype.ExternalFileType;
import org.jabref.gui.externalfiletype.ExternalFileTypes;

public class FileListDialogViewModel extends AbstractViewModel {

private final StringProperty linkProperty = new SimpleStringProperty();
private final StringProperty descriptionProperty = new SimpleStringProperty();
private final StringProperty linkProperty = new SimpleStringProperty("");
private final StringProperty descriptionProperty = new SimpleStringProperty("");
private final ListProperty<ExternalFileType> externalfilesTypes = new SimpleListProperty<>(FXCollections.emptyObservableList());

public FileListDialogViewModel() {

externalfilesTypes.set(FXCollections.observableArrayList(ExternalFileTypes.getInstance().getExternalFileTypeSelection()));

}
//

public StringProperty getLinkProperty() {
public StringProperty linkProperty() {
return linkProperty;
}

public StringProperty getDescriptionProperty() {
public StringProperty descriptionProperty() {
return descriptionProperty;
}

public ListProperty<ExternalFileType> getExternalfilesTypes() {
public ListProperty<ExternalFileType> externalFileTypeProperty() {
return externalfilesTypes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class FileListEntryEditor {
//Do not make this variable final, as then the lambda action listener will fail on compiöe
private BibDatabaseContext databaseContext;
private final ActionListener browsePressed = e -> {



String fileText = link.getText().trim();
Optional<Path> file = FileHelper.expandFilename(this.databaseContext, fileText,
Globals.prefs.getFileDirectoryPreferences());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<DialogPane prefHeight="100.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.filelist.FileLIstDialogController">
<DialogPane prefHeight="100.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.filelist.FileListDialogController">
<content>
<VBox maxWidth="1.7976931348623157E308">
<children>
Expand Down

0 comments on commit dfde523

Please sign in to comment.