Skip to content

Commit

Permalink
Merge branch 'customizeEntrydlg' of github.com:JabRef/jabref into cus…
Browse files Browse the repository at this point in the history
…tomizeEntrydlg

* 'customizeEntrydlg' of github.com:JabRef/jabref:
  fix l10n
  fix checkstyle
  add method for completely removing entry types
  remove unused import
  mark preferences service as private add result converter
  implement first part of saving customized entry types
  remove debug outout fix checkstyle
  refactorings add delete from lists
  fix issue with empty rows
  add Delete icons to table colums Code proudly reused from calixtus implementation in the preferences
  use hashmap to associate fields and types TODO: Find out why there are some invisible fields
  add new entry type to the list
  add icon buttons for adding add tostring
  add string converter for combobox
  renaming and replace combobox with textfield
  some layout improvements
  add data to table when entry type selected
  remove logger plugin needed for eclipse
  refactor to display entry types and all fields
  • Loading branch information
Siedlerchr committed Jan 30, 2020
2 parents 4ea90a2 + 0f1ff4c commit 1d448e9
Show file tree
Hide file tree
Showing 9 changed files with 408 additions and 115 deletions.
Original file line number Diff line number Diff line change
@@ -1,57 +1,189 @@
package org.jabref.gui.customentrytypes;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import javafx.beans.Observable;
import javafx.beans.property.ListProperty;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.SimpleListProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.beans.property.SimpleStringProperty;
import javafx.beans.property.StringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.util.StringConverter;

import org.jabref.Globals;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntryType;
import org.jabref.model.entry.field.BibField;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.FieldFactory;
import org.jabref.model.entry.field.FieldPriority;
import org.jabref.model.entry.field.OrFields;
import org.jabref.model.entry.field.UnknownField;
import org.jabref.model.entry.types.EntryType;
import org.jabref.model.entry.types.UnknownEntryType;
import org.jabref.preferences.PreferencesService;

import org.fxmisc.easybind.EasyBind;

public class CustomEntryTypeDialogViewModel {

public CustomEntryTypeDialogViewModel() {
public static final StringConverter<Field> FIELD_STRING_CONVERTER = new StringConverter<>() {

}
@Override
public String toString(Field object) {
return object != null ? object.getDisplayName() : "";
}

@Override
public Field fromString(String string) {
return new UnknownField(string);
}
};

private ListProperty<BibEntryType> entryTypesProperty;
private ListProperty<Field> fieldsProperty;
private ObjectProperty<BibEntryType> selectedEntryTypesProperty = new SimpleObjectProperty<>();
private ListProperty<FieldViewModel> fieldsForTypeProperty;
private ObjectProperty<Field> selectedFieldToAddProperty = new SimpleObjectProperty<>();
private StringProperty entryTypeToAddProperty = new SimpleStringProperty("");
private ObservableList<BibEntryType> entryTypes;
private ObservableList<FieldViewModel> fieldsForType = FXCollections.observableArrayList(extractor -> new Observable[] {extractor.fieldNameProperty(), extractor.fieldTypeProperty()});
private ObjectProperty<Field> newFieldToAddProperty = new SimpleObjectProperty<>();
private BibDatabaseMode mode;
private Map<BibEntryType, List<FieldViewModel>> typesWithFields = new HashMap<>();
private List<BibEntryType> typesToRemove = new ArrayList<>();

private PreferencesService preferencesService;

public CustomEntryTypeDialogViewModel(BibDatabaseMode mode, PreferencesService preferencesService) {
this.mode = mode;
this.preferencesService = preferencesService;

Collection<BibEntryType> allTypes = Globals.entryTypesManager.getAllTypes(mode);
allTypes.addAll(Globals.entryTypesManager.getAllCustomTypes(mode));

entryTypes = FXCollections.observableArrayList(allTypes);
entryTypesProperty = new SimpleListProperty<>(entryTypes);

public void addNewOptionalField2() {
// TODO Auto-generated method stub
fieldsProperty = new SimpleListProperty<>(FXCollections.observableArrayList(FieldFactory.getAllFields()));

for (BibEntryType entryType : allTypes) {
List<FieldViewModel> fields = entryType.getAllFields().stream().map(bibField -> new FieldViewModel(bibField.getField(), entryType.isRequired(bibField.getField()), bibField.getPriority(), entryType)).collect(Collectors.toList());
typesWithFields.put(entryType, fields);
}

this.fieldsForTypeProperty = new SimpleListProperty<>(fieldsForType);

EasyBind.subscribe(selectedEntryTypesProperty, type -> {
if (type != null) {
List<FieldViewModel> typesForField = typesWithFields.get(type);
fieldsForType.setAll(typesForField);
}
});

}

public void addNewOptionalField() {
// TODO Auto-generated method stub
public ListProperty<BibEntryType> entryTypesProperty() {
return this.entryTypesProperty;
}

public ListProperty<Field> fieldsProperty() {
return this.fieldsProperty;
}

public void addNewRequiredField() {
// TODO Auto-generated method stub
public enum FieldType {

REQUIRED("Required"),
OPTIONAL("Optional");

private String name;

FieldType(String name) {
this.name = name;
}

public String getDisplayName() {
return this.name;
}

@Override
public String toString() {
return this.name;
}
}

public void addNewField() {
Field field = newFieldToAddProperty.getValue();
FieldViewModel model = new FieldViewModel(field, true, FieldPriority.IMPORTANT, selectedEntryTypesProperty.getValue());
typesWithFields.computeIfAbsent(selectedEntryTypesProperty.getValue(), key -> new ArrayList<>()).add(model);
fieldsForType.add(model);
}

public void addNewCustomEntryType() {
// TODO Auto-generated method stub
EntryType newentryType = new UnknownEntryType(entryTypeToAddProperty.getValue());
BibEntryType type = new BibEntryType(newentryType, new ArrayList<>(), Collections.emptyList());
this.entryTypes.add(type);

this.typesWithFields.put(type, new ArrayList<>());
}

public Object removeEntryType(EntryType focusedItem) {
// TODO Auto-generated method stub
return null;
public ObjectProperty<BibEntryType> selectedEntryTypeProperty() {
return this.selectedEntryTypesProperty;
}

public Object removeRequiredField(Field focusedItem) {
// TODO Auto-generated method stub
return null;
public ListProperty<FieldViewModel> fieldsforTypesProperty() {
return this.fieldsForTypeProperty;
}

public Object removeOptionalField(Field focusedItem) {
// TODO Auto-generated method stub
return null;
public ObjectProperty<Field> selectedFieldToAddProperty() {
return this.selectedFieldToAddProperty;
}

public Object removeOptional2Field(Field focusedItem) {
// TODO Auto-generated method stub
return null;
public StringProperty entryTypeToAddProperty() {
return this.entryTypeToAddProperty;
}

public enum FieldType {
REQUIRED,
PRIMARY_OPTIONAL,
SECONDARY_OPTIONAL
public ObjectProperty<Field> newFieldToAddProperty() {
return this.newFieldToAddProperty;
}

public void removeEntryType(BibEntryType focusedItem) {
typesToRemove.add(focusedItem);
typesWithFields.remove(focusedItem);
entryTypes.remove(focusedItem);
}

public void removeField(FieldViewModel focusedItem) {
typesWithFields.computeIfAbsent(selectedEntryTypesProperty.getValue(), key -> new ArrayList<>()).remove(focusedItem);
fieldsForType.remove(focusedItem);
}

public void apply() {

for (var entry : typesWithFields.entrySet()) {
BibEntryType type = entry.getKey();
List<FieldViewModel> allFields = entry.getValue();

List<OrFields> requiredFields = allFields.stream().filter(field -> field.getFieldType() == FieldType.REQUIRED).map(FieldViewModel::getField).map(OrFields::new).collect(Collectors.toList());
List<BibField> otherFields = allFields.stream().filter(field -> field.getFieldType() == FieldType.OPTIONAL).map(bibField -> new BibField(bibField.getField(), bibField.getFieldPriority())).collect(Collectors.toList());

BibEntryType newType = new BibEntryType(type.getType(), otherFields, requiredFields);
Globals.entryTypesManager.addCustomOrModifiedType(newType, mode);
}

for (var type : typesToRemove) {
Globals.entryTypesManager.removeCustomEntryType(type, mode);
}
preferencesService.saveCustomEntryTypes();
}

}
Original file line number Diff line number Diff line change
@@ -1,57 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.geometry.Insets?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonType?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.DialogPane?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.TableColumn?>
<?import javafx.scene.control.TableView?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.HBox?>
<?import javafx.scene.layout.VBox?>

<DialogPane prefHeight="436.0" prefWidth="472.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.jabref.gui.customentrytypes.CustomizeEntryTypeDialogView">
<content>
<HBox minWidth="-Infinity" prefHeight="100.0" spacing="4.0">
<children>
<VBox prefHeight="200.0" prefWidth="100.0">
<children>
<Label text="Entry types" />
<TableView fx:id="entryTypes" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="entryTypColumn" prefWidth="75.0" text="Entry Type" />
<TableColumn fx:id="entryTypeActionsColumn" prefWidth="75.0" />
</columns>
</TableView>
<HBox>
<children>
<ComboBox fx:id="addNewEntryType" editable="true" prefWidth="150.0" />
<Button mnemonicParsing="false" onAction="#addEntryType" prefHeight="20.0" prefWidth="20.0" text="add" />
</children>
</HBox>
</children>
</VBox>
<VBox prefHeight="200.0" prefWidth="100.0" HBox.hgrow="ALWAYS">
<children>
<Label text="Required and optional fields" />
<TableView fx:id="requiredFields" prefHeight="200.0" prefWidth="200.0">
<columns>
<TableColumn fx:id="requiredFieldsNameColumn" prefWidth="75.0" text="Field" />
<TableColumn fx:id="fieldTypeColumn" prefWidth="75.0" text="Field type" />
<TableColumn fx:id="fieldTypeActionColumn" prefWidth="75.0" />
</columns>
</TableView>
<HBox>
<children>
<ComboBox fx:id="addNewField" editable="true" prefWidth="150.0" />
<Button mnemonicParsing="false" onAction="#addNewField" text="Button" />
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</content>
<ButtonType fx:id="applyButton" buttonData="OK_DONE" text="%Apply" />
<ButtonType fx:constant="CANCEL" />
<?import org.jabref.gui.icon.JabRefIconView?>
<?import javafx.scene.control.Tooltip?>

<DialogPane prefHeight="596.0" prefWidth="600.0"
xmlns="http://javafx.com/javafx/8.0.171"
xmlns:fx="http://javafx.com/fxml/1"
fx:controller="org.jabref.gui.customentrytypes.CustomizeEntryTypeDialogView">
<content>
<HBox minHeight="-Infinity" minWidth="-Infinity"
prefHeight="400.0" prefWidth="400.0" spacing="10.0">
<children>
<VBox prefHeight="400.0" prefWidth="100.0" spacing="10.0">
<children>
<Label text="Entry types" />
<TableView fx:id="entryTypes" minWidth="-Infinity"
VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="entryTypColumn" minWidth="100.0"
prefWidth="100.0" text="Entry Type" />
<TableColumn fx:id="entryTypeActionsColumn"
maxWidth="40.0" minWidth="40.0" resizable="false" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<HBox spacing="10.0">
<children>
<TextField fx:id="addNewEntryType" />
<Button prefHeight="20.0" prefWidth="20.0"
styleClass="icon-button,narrow" onAction="#addEntryType">
<graphic>
<JabRefIconView glyph="ADD_NOBOX" />
</graphic>
<tooltip>
<Tooltip text="%Add new entry type" />
</tooltip>
</Button>
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</HBox>
</children>
</VBox>
<VBox prefHeight="400.0" prefWidth="100.0" spacing="10.0"
HBox.hgrow="ALWAYS">
<children>
<Label text="%Required and optional fields" />
<TableView fx:id="fields" minWidth="-Infinity"
VBox.vgrow="ALWAYS">
<columns>
<TableColumn fx:id="fieldNameColumn"
minWidth="150.0" prefWidth="-1.0" text="%Field" />
<TableColumn fx:id="fieldTypeColumn"
minWidth="100.0" prefWidth="100.0" text="%Field type" />
<TableColumn fx:id="fieldTypeActionColumn"
maxWidth="40.0" minWidth="40.0" resizable="false" />
</columns>
<columnResizePolicy>
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
</columnResizePolicy>
</TableView>
<HBox spacing="10.0">
<children>
<ComboBox fx:id="addNewField" editable="true"
prefWidth="150.0" />
<Button prefHeight="20.0" prefWidth="20.0"
styleClass="icon-button,narrow" onAction="#addNewField">
<graphic>
<JabRefIconView glyph="ADD_NOBOX" />
</graphic>
<tooltip>
<Tooltip text="%Add new Field" />
</tooltip>
</Button>
</children>
</HBox>
</children>
</VBox>
</children>
</HBox>
</content>
<ButtonType fx:id="applyButton" buttonData="OK_DONE"
text="%Apply" />
<ButtonType fx:constant="CANCEL" />
</DialogPane>
Loading

0 comments on commit 1d448e9

Please sign in to comment.