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

Shared database synchronized by FocusChangedEvent #6771

Merged
merged 8 commits into from
Sep 1, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
15 changes: 15 additions & 0 deletions src/main/java/org/jabref/gui/entryeditor/EntryEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ public class EntryEditor extends BorderPane {
private BibEntry entry;
private SourceTab sourceTab;

/*
* Field that is focused at the moment
*/
private Field isFocusedField;

/*
* tabs to be showed in GUI
* */
Expand Down Expand Up @@ -156,6 +161,8 @@ public EntryEditor(BasePanel panel, ExternalFileTypes externalFileTypes) {
event.setDropCompleted(success);
event.consume();
});

this.isFocusedField = null;
}

/**
Expand Down Expand Up @@ -371,16 +378,24 @@ public void setFocusToField(Field field) {
FieldsEditorTab fieldsEditorTab = (FieldsEditorTab) tab;
tabbed.getSelectionModel().select(tab);
fieldsEditorTab.requestFocus(field);
this.isFocusedField = field;
// Adopt focused Field from EntryEditor to BibEntry
entry.setFocusedField(this.isFocusedField);
}
}
});
}

public Field getFocusedField() {
return this.isFocusedField;
}

public void nextPreviewStyle() {
this.entryEditorTabs.forEach(EntryEditorTab::nextPreviewStyle);
}

public void previousPreviewStyle() {
this.entryEditorTabs.forEach(EntryEditorTab::previousPreviewStyle);
}

}
18 changes: 18 additions & 0 deletions src/main/java/org/jabref/logic/shared/DBMSSynchronizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jabref.model.entry.event.EntriesEvent;
import org.jabref.model.entry.event.EntriesEventSource;
import org.jabref.model.entry.event.FieldChangedEvent;
import org.jabref.model.entry.event.FocusChangedEvent;
import org.jabref.model.metadata.MetaData;
import org.jabref.model.metadata.event.MetaDataChangedEvent;
import org.jabref.model.util.FileUpdateMonitor;
Expand Down Expand Up @@ -136,6 +137,23 @@ public void listen(MetaDataChangedEvent event) {
}
}

/**
* Listening method. Updates an existing shared {@link BibEntry} by focus request.
*
* @param event {@link FocusChangedEvent} object
*/
@Subscribe
public void listen(FocusChangedEvent event) {
Copy link
Member

Choose a reason for hiding this comment

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

I think the problem is that you are listening to an Event from the EventBus which is nowhere fired

// While synchronizing the local database (see synchronizeLocalDatabase() below), some EntriesEvents may be posted.
// In this case DBSynchronizer should not try to update the bibEntry entry again (but it would not harm).
if (isPresentLocalBibEntry(event.getBibEntry()) && isEventSourceAccepted(event) && checkCurrentConnection()) {
synchronizeLocalMetaData();
BibEntry bibEntry = event.getBibEntry();
synchronizeSharedEntry(bibEntry);
synchronizeLocalDatabase(); // Pull changes for the case that there were some
}
}

/**
* Sets the table structure of shared database if needed and pulls all shared entries to the new local database.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public synchronized void listen(@SuppressWarnings("unused") BibDatabaseContextCh
// Only relay event if the field changes are more than one character or a new field is edited
FieldChangedEvent fieldChange = (FieldChangedEvent) event;
boolean isEditOnNewField = lastFieldChanged == null || !lastFieldChanged.equals(fieldChange.getField());
// Only deltas of 1 registered by fieldChange
boolean isMajorChange = fieldChange.getDelta() >= 1;

if (fieldChange.getDelta() > 1 || isEditOnNewField) {
if (isEditOnNewField) {
lastFieldChanged = fieldChange.getField();
Copy link
Member

Choose a reason for hiding this comment

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

See the eventBus.post method, the eventBus post method is reposinsible for firing the event.

eventBus.post(event);
}
Expand Down
19 changes: 19 additions & 0 deletions src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.jabref.model.entry.event.EntriesEventSource;
import org.jabref.model.entry.event.FieldAddedOrRemovedEvent;
import org.jabref.model.entry.event.FieldChangedEvent;
import org.jabref.model.entry.event.FocusChangedEvent;
import org.jabref.model.entry.field.Field;
import org.jabref.model.entry.field.InternalField;
import org.jabref.model.entry.field.OrFields;
Expand Down Expand Up @@ -86,6 +87,11 @@ public class BibEntry implements Cloneable {
*/
private boolean changed;

/*
* Field that is focused by the BasePanel right now
*/
private Field isFocusedField;

/**
* Constructs a new BibEntry. The internal ID is set to IdGenerator.next()
*/
Expand Down Expand Up @@ -951,6 +957,19 @@ public Optional<FieldChange> addFile(int index, LinkedFile file) {
return setFiles(linkedFiles);
}

public Field getFocusedField() {
return this.isFocusedField;
}

public void setFocusedField(Field isFocused, EntriesEventSource eventSource) {
this.isFocusedField = isFocused;
eventBus.post(new FocusChangedEvent(this, isFocused, eventSource));
}

public void setFocusedField(Field isFocused) {
this.setFocusedField(isFocused, EntriesEventSource.LOCAL);
}

public ObservableMap<Field, String> getFieldsObservable() {
return fields;
}
Expand Down
37 changes: 37 additions & 0 deletions src/main/java/org/jabref/model/entry/event/FocusChangedEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package org.jabref.model.entry.event;

import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.field.Field;

/**
* <code>FocusChangedEvent</code> is fired when the focus of a field of <code>BibEntry</code> has been requested.
*/

public class FocusChangedEvent extends EntryChangedEvent {

private final Field field;

/**
* @param bibEntry Affected BibEntry object
* @param field Name of field which focus has been requested
* @param location location Location affected by this event
*/
public FocusChangedEvent(BibEntry bibEntry, Field field, EntriesEventSource location) {
super(bibEntry, location);
this.field = field;
}

/**
* @param bibEntry Affected BibEntry object
* @param field Name of field which focus has been requested
*/
public FocusChangedEvent(BibEntry bibEntry, Field field) {
super(bibEntry);
this.field = field;
}

public Field getField() {
return field;
}

}