Skip to content

Commit

Permalink
Merge pull request #746 from oscargus/lessnullcheck
Browse files Browse the repository at this point in the history
A few less nulls
  • Loading branch information
simonharrer committed Jan 30, 2016
2 parents 0ed73b2 + 1d695fb commit 12810a5
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 32 deletions.
6 changes: 3 additions & 3 deletions src/main/java/net/sf/jabref/gui/BasePanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1084,16 +1084,16 @@ public void action() {
// Note that we can't put the number of entries that have been reverted into the undoText as the concrete number cannot be injected
actions.put(Relevance.getInstance().getValues().get(0).getActionName(),
new SpecialFieldAction(frame, Relevance.getInstance(),
Relevance.getInstance().getValues().get(0).getFieldValue(), true,
Relevance.getInstance().getValues().get(0).getFieldValue().get(), true,
Localization.lang("Toggle relevance"),
Localization.lang("Toggled relevance for %0 entries")));
actions.put(Quality.getInstance().getValues().get(0).getActionName(),
new SpecialFieldAction(frame, Quality.getInstance(),
Quality.getInstance().getValues().get(0).getFieldValue(), true,
Quality.getInstance().getValues().get(0).getFieldValue().get(), true,
Localization.lang("Toggle quality"),
Localization.lang("Toggled quality for %0 entries")));
actions.put(Printed.getInstance().getValues().get(0).getActionName(), new SpecialFieldAction(frame,
Printed.getInstance(), Printed.getInstance().getValues().get(0).getFieldValue(), true,
Printed.getInstance(), Printed.getInstance().getValues().get(0).getFieldValue().get(), true,
Localization.lang("Toggle print status"),
Localization.lang("Toggled print status for %0 entries")));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void mouseClicked(MouseEvent e) {
}

// Check if the clicked colum is a specialfield column
if(modelColumn.isIconColumn() && (SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(modelColumn.getColumnName())!=null)) {
if (modelColumn.isIconColumn() && (SpecialFieldsUtils.isSpecialField(modelColumn.getColumnName()))) {
// handle specialfield
handleSpecialFieldLeftClick(e, modelColumn.getColumnName());
} else if (modelColumn.isIconColumn()) { // left click on icon field
Expand Down Expand Up @@ -419,8 +419,10 @@ private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn colum
showDefaultPopup = false;
}
} else {
SpecialField specialField = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(column.getColumnName());
if (specialField == null) {
if (SpecialFieldsUtils.isSpecialField(column.getColumnName())) {
// full pop should be shown as left click already shows short popup
showDefaultPopup = true;
} else {
if (entry.hasField(field)) {
String content = entry.getField(field);
Icon icon;
Expand All @@ -434,9 +436,6 @@ private void showIconRightClickMenu(MouseEvent e, int row, MainTableColumn colum
panel.metaData(), field));
showDefaultPopup = false;
}
} else {
// full pop should be shown as left click already shows short popup
showDefaultPopup = true;
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/net/sf/jabref/specialfields/SpecialField.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,8 @@ void setValues(List<SpecialFieldValue> values) {
this.keywords = new ArrayList<>();
this.map = new HashMap<>();
for (SpecialFieldValue v : values) {
if (v.getKeyword() != null) {
keywords.add(v.getKeyword());
}
if (v.getFieldValue() != null) {
map.put(v.getFieldValue(), v);
}
v.getKeyword().ifPresent(keywords::add);
v.getFieldValue().ifPresent(fieldValue -> map.put(fieldValue, v));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
import net.sf.jabref.JabRef;

/**
* Listener triggering
* Listener triggering
* * an update of keywords if special field has been updated
* * an update of special fields if keywords have been updated
* * an update of special fields if keywords have been updated
*/
public class SpecialFieldUpdateListener implements VetoableChangeListener {

Expand All @@ -40,17 +40,17 @@ public void vetoableChange(PropertyChangeEvent e)
final BibEntry entry = (BibEntry) e.getSource();
final String fieldName = e.getPropertyName();
// Source editor cycles through all entries
// if we immediately updated the fields, the entry editor would detect a subsequent change as a user change
// if we immediately updated the fields, the entry editor would detect a subsequent change as a user change
// and re-fire this event
// e.g., "keyword = {prio1}, priority = {prio2}" and a change at keyword to prio3 would not succeed.
// e.g., "keyword = {prio1}, priority = {prio2}" and a change at keyword to prio3 would not succeed.
SwingUtilities.invokeLater(new Runnable() {

@Override
public void run() {
if ("keywords".equals(fieldName)) {
// we do NOT pass a named component indicating that we do not want to have undo capabilities
// if the user undoes the change in the keyword field, this method is also called and
// the special fields are updated accordingly
// if the user undoes the change in the keyword field, this method is also called and
// the special fields are updated accordingly
SpecialFieldsUtils.syncSpecialFieldsFromKeywords(entry, null);
SwingUtilities.invokeLater(new Runnable() {

Expand All @@ -60,11 +60,10 @@ public void run() {
}
});
} else {
SpecialField field = SpecialFieldsUtils.getSpecialFieldInstanceFromFieldName(fieldName);
if (field != null) {
if (SpecialFieldsUtils.isSpecialField(fieldName)) {
// we do NOT pass a named component indicating that we do not want to have undo capabilities
// if the user undoes the change in the sepcial field, this method is also called and
// the keyword field is updated accordingly
// if the user undoes the change in the special field, this method is also called and
// the keyword field is updated accordingly
SpecialFieldsUtils.syncKeywordsFromSpecialFields(entry, null);
SwingUtilities.invokeLater(new Runnable() {

Expand Down
16 changes: 9 additions & 7 deletions src/main/java/net/sf/jabref/specialfields/SpecialFieldValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package net.sf.jabref.specialfields;

import java.util.Optional;

import javax.swing.*;

import net.sf.jabref.gui.JabRefFrame;
Expand Down Expand Up @@ -42,10 +44,10 @@ public class SpecialFieldValue {


// value when used in a separate vield
//private String fieldValue;
//private String fieldValue;

/**
*
*
* @param field The special field this value is a value of
* @param keyword - The keyword to be used at BibTex's keyword field. May be "null" if no keyword is to be set
* @param actionName - the action to call
Expand All @@ -68,8 +70,8 @@ public SpecialFieldValue(
this.toolTipText = toolTipText;
}

public String getKeyword() {
return this.keyword;
public Optional<String> getKeyword() {
return Optional.ofNullable(this.keyword);
}

public String getActionName() {
Expand All @@ -86,8 +88,8 @@ public JLabel createLabel() {
return label;
}

public String getFieldValue() {
return this.keyword;
public Optional<String> getFieldValue() {
return Optional.ofNullable(this.keyword);
}

public Icon getIcon() {
Expand All @@ -103,7 +105,7 @@ public SpecialFieldAction getAction(JabRefFrame frame) {
action = new SpecialFieldAction(
frame,
this.field,
this.getFieldValue(),
this.getFieldValue().get(),
// if field contains only one value, it has to be nulled
// otherwise, another setting does not empty the field
this.field.getValues().size() == 1,
Expand Down

0 comments on commit 12810a5

Please sign in to comment.