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 New entry dialog to javafx #4312

Merged
merged 22 commits into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
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