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

Support CitationStyles #1928

Merged
merged 20 commits into from
Sep 22, 2016
Merged

Support CitationStyles #1928

merged 20 commits into from
Sep 22, 2016

Conversation

chriba
Copy link
Contributor

@chriba chriba commented Sep 6, 2016

Implements #119.

The User can choose multiple CitationStyles which he can cycle threw in the preview panel (forward with F9, backwards shift + F9, both are in the context menu and the menu bar) .
As discussed I removed the 2nd Preview.

Preview before:

preview_before

Preview after:

preview_after

Preferences before:

preferences_before

Preferences after:

preferences_after

I didn't include the localization (other the English) on purpose because they create unnecessary conflicts when rebasing quite often (I push them when everything else is fine).

The Help page has to be updated too. I do that as soon as this PR is merged.

  • Change in CHANGELOG.md described
  • Tests created for changes
  • Screenshots added (for bigger UI changes)
  • Manually tested changed features in running JabRef
  • Check documentation status (Issue created for outdated help page at help.jabref.org?)

Warning: currently I read the available CitationStyles at runtime. I had problems reading them from the gradle dependency thus currently they are only found when JabRef is started from the JAR.

@boceckts
Copy link
Contributor

The text of the preferences tab is not completely visible, either reword or adjust the width of the side panel.

@@ -638,8 +642,12 @@ public void windowClosing(WindowEvent e) {
return;
}

if (bp.getPreviewPanel() != null) {
bp.getPreviewPanel().updateLayout();
Copy link
Contributor

Choose a reason for hiding this comment

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

Please rename

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@boceckts
Copy link
Contributor

When pressing the up or down button the selected entry becomes deselected and I have to select it again, this can be quite frustrating if I want to move a citation style to the top. Can you please change it so the selected entry stays selected?

if (CitationStyle.isCitationStyleFile(style)){
chosenModel.addElement(CitationStyle.createCitationStyleFromFile(style));
}
else {
Copy link
Contributor

Choose a reason for hiding this comment

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

Weird formatting, move this to the end of the line above.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@boceckts
Copy link
Contributor

boceckts commented Sep 10, 2016

The preview panel is not being updated after changing the citation style but rather displays always the first selected entry.

Steps to reproduce:

  1. go to preferences and add a citation style
  2. In the main table select an entry and open the preview panel
  3. press F9 to see the newly added citation style
  4. select a different entry and the preview panel will not update but use the information of the first selected entry EDIT: it will update the citation style though

@boceckts
Copy link
Contributor

The preview panel is not being updated after changing the citation style when working with multiple databases.

Steps to reproduce:

  1. go to preferences and add a citation style
  2. open at least two databases with at least one entry
  3. in the main table select an entry and open the preview panel
  4. select the second database and an entry
  5. press F9 to change to the newly added citation style
  6. the preview panel will not update at all but the status says the citation style has changed
    When switching to the first database the preview panel has updated and responds to citation style changes.

@boceckts
Copy link
Contributor

I think it would be great to also add the selected citation styles to the "Export to clipboard" dialog.

import org.apache.commons.logging.LogFactory;


public class CitationStyleWorker extends SwingWorker<String, Void> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a javadoc comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@boceckts
Copy link
Contributor

When the bugs are fixed and the other minor comments have been addressed then it's fine by me.

@@ -118,6 +121,12 @@ dependencies {
compile 'org.apache.logging.log4j:log4j-api:2.6.2'
compile 'org.apache.logging.log4j:log4j-core:2.6.2'

// need to use snapshots as the stable version is from 2013 and doesn't support v1.0.1 CitationStyles
compile 'org.citationstyles:styles:1.0.1-SNAPSHOT'
Copy link
Member

Choose a reason for hiding this comment

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

Please also follow https://github.com/JabRef/jabref/blob/master/CONTRIBUTING.md#when-adding-a-library

Is there an issue asking for a release of the library? - If yes, please link it here and open an issue at jabref/issues linking that issue. If no, please either contact the maintainers directly or open an issue at their repo. Also open an issue at jabref/issues.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@chriba
Copy link
Contributor Author

chriba commented Sep 12, 2016

Fixed the Bug (both were caused by the same thing)
Is the Export to clipboard important? You can already copy the current preview via context menu on the preview panel.

@koppor
Copy link
Member

koppor commented Sep 12, 2016

The context menu exports text only. Is it possible to export the HTML? When pasting into Microsoft Word, everything is formatted correctly.

The "export to clipboard" is not important. If some interested user requests it, work on it can be done.

@@ -12,6 +12,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
## [Unreleased]

### Changed
- Added support for over 1000 (self updating) 1.0.1 Citation Styles
- You can set and cycle different preview Styles (including CitationStyles)
Copy link
Member

Choose a reason for hiding this comment

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

"styles" with lower case s

/**
* WARNING: The generation of a citation may take some time, better call it in outside the main Thread
*/
public class CitationStyleGenerator {
Copy link
Member

Choose a reason for hiding this comment

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

You can also mark the class as protected so that nobody outside of the package can use it (i.e. everybody is forced to use the cache).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

^done

Copy link
Contributor Author

Choose a reason for hiding this comment

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

why not package-private?

Copy link
Member

Choose a reason for hiding this comment

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

I don't like package-private (because writing nothing looks like somebody just forgot to specify the correct visibility)

@koppor koppor changed the title Support CitationStyles upport CitationStyles Sep 15, 2016
@koppor koppor changed the title upport CitationStyles Support CitationStyles Sep 15, 2016
Copy link
Member

@tobiasdiez tobiasdiez left a comment

Choose a reason for hiding this comment

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

The code looks really good. Just some minor remarks (mostly around Optionals) and please add a few tests.

@@ -20,6 +20,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- The search result Window won't stay on top anymore if the main Window is focused and will be present in the taskbar
- The user can jump from the searchbar to the maintable with `ctrl+enter`
- Implemented [#573 (comment)](https://github.com/JabRef/jabref/issues/573#issuecomment-232284156): Added shortcut: closing the search result window with `ctrl+w`
- Added support for over 1000 1.0.1 CitationStyles
Copy link
Member

Choose a reason for hiding this comment

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

Maybe reformulate to 1000 citation styles (using CitationStyles 1.0.1) and add link.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

String style = previewPreferences.getPreviewCycle().get(previewPreferences.getCyclePreviewPosition());

if (CitationStyle.isCitationStyleFile(style)) {
if (getBasePanel() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

basepanel.ifPresent(...) and maybe remove getBasePanel

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}
} else {
updatePreviewLayout(previewPreferences.getPreviewStyle());
if (getBasePanel() != null) {
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


if (citationStyleWorker != null){
Copy link
Member

@tobiasdiez tobiasdiez Sep 15, 2016

Choose a reason for hiding this comment

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

Make citationStyleWorker also an Optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

.addSearchListener(previewPanel[1]);

this.preview = previewPanel[activePreview];
if (panel.getPreviewPanel() != null){
Copy link
Member

Choose a reason for hiding this comment

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

Make getPreviewPanel return an Optional

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

public void setCitationStyle(CitationStyle citationStyle) {
if (citationStyle == null || this.citationStyle == citationStyle) {
Copy link
Member

Choose a reason for hiding this comment

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

I would guard citationStyle from being null (Objects.requireNonNull).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

if (citationStyle == null || this.citationStyle == citationStyle) {
return;
}
if (this.citationStyle == null || !this.citationStyle.getSource().equals(citationStyle.getSource())) {
Copy link
Member

Choose a reason for hiding this comment

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

Overwrite equals in CitationStyle and reuse here.

Copy link
Contributor Author

@chriba chriba Sep 19, 2016

Choose a reason for hiding this comment

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

done

*/
@Subscribe
public void listen(EntryChangedEvent entryChangedEvent) {
if (entryChangedEvent != null && entryChangedEvent.getBibEntry() != null){
Copy link
Member

Choose a reason for hiding this comment

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

Can the event and/or the BibEntry ever be null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The event itself shouldn't be null, for its properties there are no null checks.

Copy link
Member

Choose a reason for hiding this comment

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

Then just add Objects.requireNonNull(entryChangedEvent) and remove the != null check.

Copy link
Member

Choose a reason for hiding this comment

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

Further please investigate the "call hierarchy" whether getBibEntry() may ever be null. I don't think so. Thus, please add Objects.requireNonNull(entryChangedEvent.getBibEntry();.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it not more useful to add the Objects.requireNonNull to the constructor of the EntryEvent?

Copy link
Member

Choose a reason for hiding this comment

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

The more places the better

LOGGER.error("Bad character inside BibEntry", e);
// sadly one can not easily retrieve the bad char from the TokenMgrError
return new StringBuilder()
.append(Localization.lang("Bad character inside BibEntry"))
Copy link
Member

Choose a reason for hiding this comment

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

Use a proper word instead of BibEntry (no idea what we usually use...probably entry)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

entrywas used in other translations

Copy link
Member

Choose a reason for hiding this comment

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

Just look at other localizations.

Please write cannot

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

public void getDefault() throws Exception {
Assert.assertNotNull(CitationStyle.getDefault());
}

Copy link
Member

Choose a reason for hiding this comment

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

Please add some tests. At least one test should verify that a BibEntry is properly converted into the correct string.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added a Test to check the generated citation with the default citation style on the test bibEntry.

this.basePanel = Optional.ofNullable(panel);

createPreviewPane();
updateLayout();

if (panel != null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Use this.basePanel instead here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

this.preferences = preferences;
}

public static void putDefaults(Map<String, Object> defaults) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Although there are some classes that use this, as far as I know, the decision is that all constants and all defaults setting should be in JabRefPreferences.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They are back in JabRefPreferences.

@Olifair
Copy link

Olifair commented Sep 27, 2016

Is the use of Citation Styles only for the preview pane ? I have downloaded the latest developer version and connected to a LibreOffice document to see if I could use the CSL styles to format my bibliography, but when I open the "Select style" window, only the jstyle format seems to be supported.

@georgd
Copy link

georgd commented Oct 7, 2016

I think, this would be the next logical step: to use Citation Styles in Libre Office.

@koppor
Copy link
Member

koppor commented Oct 8, 2016

Please open a new issue to offer tracking the status. Maybe @oscargus has some time to work on that.

zesaro pushed a commit to zesaro/jabref that referenced this pull request Nov 22, 2016
@wujastyk
Copy link

wujastyk commented Jan 5, 2017

If I use Biblatex style biblio entries, then I have fields like "journaltitle," "location," and "date" instead of "journal," "address," and "year." These are not picked up by the new Preview citation styles.

Further, as reported by boceckts above, one can't get the citation style displayed, so as to edit it.

The whole new Preview citation feature is wonderfully helpful. I use it a lot! Thank you.

@koppor koppor removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Oct 6, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants