Skip to content

Commit

Permalink
Convert New entry dialog to javafx (#4312)
Browse files Browse the repository at this point in the history
* convert the NewEntryType Dialog to javafx

* delete useless class file

* fix order and empty else statement

* fix pdfImport old dialog problem

* rework fxml code
add title pane
add bindings
Create view model todo

Co-authored-by: 1160300608 <[email protected]>

* use managed properties, pass dialog service as argument

* fix checkstyle

* add new prefereces method for getting and setting last used id based fetchr
bind combobox directly to fetcher
improve binding
pass preferences to constructor
delete obsolete gui test class and old dialog

* improve layout, move id grid pane to bottom, remove third col

* refactor and extract data to ViewModel
TODO: merge insertentry and newEntry in basePanel

* fix checkstyle

* fix result converter

* remove newEntry method, replcae with insertEntry
fix event handler

* refactor task and add value property to select last used fetcher

* fix l10nn

* fix l10n

* refactor code some more

* fix checkstyle
  • Loading branch information
Siedlerchr authored Sep 9, 2018
1 parent 3d1bc8a commit 4c7194a
Show file tree
Hide file tree
Showing 15 changed files with 501 additions and 710 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/jabref/gui/AbstractViewModel.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package org.jabref.gui;

public class AbstractViewModel {

//empty
}
62 changes: 4 additions & 58 deletions src/main/java/org/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
Expand Down Expand Up @@ -110,7 +109,6 @@
import org.jabref.model.database.shared.DatabaseLocation;
import org.jabref.model.database.shared.DatabaseSynchronizer;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryType;
import org.jabref.model.entry.FieldName;
import org.jabref.model.entry.InternalBibtexFields;
import org.jabref.model.entry.LinkedFile;
Expand Down Expand Up @@ -761,58 +759,6 @@ public void registerUndoableChanges(SaveSession session) {
}
}

/**
* This method is called from JabRefFrame when the user wants to create a new entry. If the argument is null, the
* user is prompted for an entry type.
*
* @param type The type of the entry to create.
* @return The newly created BibEntry or null the operation was canceled by the user.
*/
public BibEntry newEntry(EntryType type) {
EntryType actualType = type;
if (actualType == null) {
// Find out what type is wanted.
final EntryTypeDialog etd = new EntryTypeDialog(frame);
// We want to center the dialog, to make it look nicer.
etd.setVisible(true);
actualType = etd.getChoice();
}
if (actualType != null) { // Only if the dialog was not canceled.
final BibEntry be = new BibEntry(actualType.getName());
try {
bibDatabaseContext.getDatabase().insertEntry(be);
// Set owner/timestamp if options are enabled:
List<BibEntry> list = new ArrayList<>();
list.add(be);
UpdateField.setAutomaticFields(list, true, true, Globals.prefs.getUpdateFieldPreferences());

// Create an UndoableInsertEntry object.
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), be));
output(Localization.lang("Added new '%0' entry.", actualType.getName().toLowerCase(Locale.ROOT)));

// We are going to select the new entry. Before that, make sure that we are in
// show-entry mode. If we aren't already in that mode, enter the WILL_SHOW_EDITOR
// mode which makes sure the selection will trigger display of the entry editor
// and adjustment of the splitter.
if (mode != BasePanelMode.SHOWING_EDITOR) {
mode = BasePanelMode.WILL_SHOW_EDITOR;
}

clearAndSelect(be);

// The database just changed.
markBaseChanged();

this.showAndEdit(be);

return be;
} catch (KeyCollisionException ex) {
LOGGER.info(ex.getMessage(), ex);
}
}
return null;
}

/**
* This method is called from JabRefFrame when the user wants to create a new entry.
*
Expand All @@ -822,10 +768,10 @@ public void insertEntry(final BibEntry bibEntry) {
if (bibEntry != null) {
try {
bibDatabaseContext.getDatabase().insertEntry(bibEntry);
if (Globals.prefs.getBoolean(JabRefPreferences.USE_OWNER)) {
// Set owner field to default value
UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs.getUpdateFieldPreferences());
}

// Set owner and timestamp
UpdateField.setAutomaticFields(bibEntry, true, true, Globals.prefs.getUpdateFieldPreferences());

// Create an UndoableInsertEntry object.
getUndoManager().addEdit(new UndoableInsertEntry(bibDatabaseContext.getDatabase(), bibEntry));
output(Localization.lang("Added new '%0' entry.", bibEntry.getType()));
Expand Down
76 changes: 76 additions & 0 deletions src/main/java/org/jabref/gui/EntryType.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.control.TitledPane?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.ColumnConstraints?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.layout.RowConstraints?>
<?import javafx.scene.layout.VBox?>

<DialogPane xmlns="http://javafx.com/javafx/8.0.141" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.EntryTypeView">
<content>
<BorderPane>
<top>
<VBox prefHeight="200.0" prefWidth="400.0" BorderPane.alignment="CENTER">
<children>
<TitledPane fx:id="biblatexTitlePane" animated="false" collapsible="false" text="Biblatex">
<content>
<FlowPane fx:id="biblatexPane" prefHeight="200.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane fx:id="bibTexTitlePane" animated="false" collapsible="false" text="BibTeX">
<content>
<FlowPane fx:id="bibTexPane" prefHeight="200.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane fx:id="ieeeTranTitlePane" animated="false" collapsible="false" text="IEEETran">
<content>
<FlowPane fx:id="ieeetranPane" prefHeight="200.0" prefWidth="200.0" />
</content>
</TitledPane>
<TitledPane fx:id="customTitlePane" animated="false" collapsible="false" text="%Custom">
<content>
<FlowPane fx:id="customPane" prefHeight="200.0" prefWidth="200.0" />
</content>
</TitledPane>
</children>
</VBox>
</top>
<bottom>
<GridPane alignment="CENTER" BorderPane.alignment="CENTER">
<children>
<Label text="%ID type" />
<ComboBox fx:id="idBasedFetchers" prefHeight="30.0" prefWidth="300.0" GridPane.columnIndex="1" onAction="#focusTextField" />
<Label text="%ID" GridPane.rowIndex="1" />
<TextField fx:id="idTextField" prefHeight="30.0" prefWidth="300.0" GridPane.columnIndex="1" GridPane.rowIndex="1" onAction="#runFetcherWorker"/>
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" maxWidth="122.0" minWidth="10.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" maxWidth="146.0" minWidth="10.0" prefWidth="300.0" />
</columnConstraints>
<opaqueInsets>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</opaqueInsets>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<padding>
<Insets bottom="4.0" left="4.0" right="4.0" top="4.0" />
</padding>
</GridPane>
</bottom>
</BorderPane>
</content>
<buttonTypes>
<ButtonType fx:constant="CANCEL" />
<ButtonType fx:id="generateButton" buttonData="OK_DONE" text="%Generate" />
</buttonTypes>
</DialogPane>
Loading

0 comments on commit 4c7194a

Please sign in to comment.