Skip to content

Commit

Permalink
Upgrade 3rd party jpicker to fix null pointer on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
bdionne committed Feb 27, 2023
1 parent a481ea8 commit 0789938
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 65 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<groupId>gov.nih.nci</groupId>
<artifactId>evs-history</artifactId>
<version>1.0.5-SNAPSHOT</version>
<version>1.0.6-SNAPSHOT</version>
<packaging>bundle</packaging>

<name>EVS History Plugin</name>
Expand Down Expand Up @@ -58,7 +58,7 @@
<dependency>
<groupId>org.jdatepicker</groupId>
<artifactId>jdatepicker</artifactId>
<version>1.3.4</version>
<version>2.0.0-SNAPSHOT</version>
</dependency>


Expand Down
100 changes: 39 additions & 61 deletions src/main/java/gov/nih/nci/evs/EVSHistoryPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
Expand All @@ -22,6 +23,7 @@
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFormattedTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
Expand All @@ -31,11 +33,11 @@
import javax.swing.ScrollPaneConstants;
import javax.swing.border.EmptyBorder;

import org.jdatepicker.impl.*;
import org.jdatepicker.impl.JDatePanelImpl;
import org.jdatepicker.impl.JDatePickerImpl;


import org.jdatepicker.DateComponentFormatter;
import org.jdatepicker.DateModel;
import org.jdatepicker.JDatePanel;
import org.jdatepicker.JDatePicker;
import org.jdatepicker.UtilDateModel;
import org.protege.editor.core.prefs.Preferences;
import org.protege.editor.core.prefs.PreferencesManager;
import org.protege.editor.owl.OWLEditorKit;
Expand All @@ -50,8 +52,8 @@ public class EVSHistoryPanel extends JPanel implements ActionListener {

private static final Logger log = LoggerFactory.getLogger(EVSHistoryPanel.class);

private JDatePickerImpl startdatePicker;
private JDatePickerImpl enddatePicker;
private JDatePicker startdatePicker;
private JDatePicker enddatePicker;
private JTextField usernameField;
private JTextField codeField;
private JComboBox operationCombobox;
Expand All @@ -63,7 +65,6 @@ public class EVSHistoryPanel extends JPanel implements ActionListener {
private EVSHistoryTableModel tableModel;

private OWLEditorKit owlEditorKit;
private OWLClass selected = null;
protected static final String LAST_USED_FOLDER = "";

enum OPERATION {ALL, CREATE, MODIFY, SPLIT, MERGE, RETIRE};
Expand Down Expand Up @@ -133,13 +134,9 @@ private JPanel createTopComponent( ) {
UtilDateModel startmodel = new UtilDateModel();
startmodel.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
startmodel.setSelected(true);
Properties p = new Properties();
p.put("text.today", "today");
p.put("text.month", "month");
p.put("text.year", "year");
DateComponentFormatter dateFormatter = new DateComponentFormatter();
JDatePanelImpl datePanel = new JDatePanelImpl(startmodel, p);
startdatePicker = new JDatePickerImpl(datePanel, dateFormatter);

JDatePanel datePanel = new JDatePanel(startmodel);
startdatePicker = new JDatePicker(startmodel);
Dimension dm = startdatePicker.getPreferredSize();
datePanel.setPreferredSize(new Dimension(dm.width + 100, 220));
startdatePicker.setPreferredSize(new Dimension(dm.width + 50, dm.height));
Expand Down Expand Up @@ -195,8 +192,8 @@ private JPanel createTopComponent( ) {
cal.setTime(new Date());
endmodel.setDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
endmodel.setSelected(true);
JDatePanelImpl enddatePanel = new JDatePanelImpl(endmodel, p);
enddatePicker = new JDatePickerImpl(enddatePanel, dateFormatter);
JDatePanel enddatePanel = new JDatePanel(endmodel);
enddatePicker = new JDatePicker(endmodel);
enddatePanel.setPreferredSize(new Dimension(dm.width + 100, 220));
enddatePicker.setPreferredSize(new Dimension(dm.width + 50, dm.height));
enddatePicker.setBorder(emptyBorder);
Expand Down Expand Up @@ -228,22 +225,16 @@ private JScrollPane createCenterComponent() {
JScrollPane sPane = new JScrollPane(evsHistoryTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
return sPane;

//tablePanel.add(new JScrollPane(evsHistoryTable, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER));
//return tablePanel;
}

private JPanel createBottomComponent() {
JPanel panel = new JPanel();
panel.setPreferredSize(new Dimension(300, 40));
panel.setLayout(new FlowLayout(FlowLayout.CENTER));
//refresh = new JButton("Refresh");
export = new JButton("Export");

//.addActionListener(this);
export.addActionListener(this);

//panel.add(refresh);
//panel.add(Box.createHorizontalStrut(100));
panel.add(export);
return panel;
}
Expand All @@ -259,7 +250,6 @@ public void populateEVSHistoryTable( ) {
}

public void setSelectedClass(OWLClass cls) {
selected = cls;
}

public void disposeView() {
Expand All @@ -268,56 +258,44 @@ public void disposeView() {

@Override
public void actionPerformed(ActionEvent e) {

if ( e.getSource() == executeBtn ) {
String startdate = startdatePicker.getJFormattedTextField().getText();
String enddate = enddatePicker.getJFormattedTextField().getText();

DateFormat dateFormatter = new SimpleDateFormat("MMM dd, yyyy");
Date startDate = null;
Date endDate = null;

if (startdate != null && !startdate.isEmpty()) {
try {
startDate = dateFormatter.parse(startdate);
} catch (ParseException ex) {
JOptionPane.showMessageDialog(this, "Please select a start date from Calendar.");
}
}
if (enddate != null && !enddate.isEmpty()) {
try {
endDate = dateFormatter.parse(enddate);
} catch (ParseException ex) {
JOptionPane.showMessageDialog(this, "Please select an end date from Calendar.");
}
}
if (startDate != null && endDate != null) {
if (startDate.after(endDate)) {
JOptionPane.showMessageDialog(this, "Start date can not be later than end date.");
return;
}

DateModel<?> sdm = startdatePicker.getModel();
DateModel<?> edm = enddatePicker.getModel();


Calendar start_cal = Calendar.getInstance();

start_cal.set(sdm.getYear(), sdm.getMonth(), sdm.getDay(), 0, 0, 0);

Calendar end_cal = Calendar.getInstance();

end_cal.set(edm.getYear(), edm.getMonth(), edm.getDay(), 0, 0, 0);

if (start_cal.after(end_cal)) {
JOptionPane.showMessageDialog(this, "Start date can not be later than end date.");
return;
}

String username = usernameField.getText();
String code = codeField.getText();
String operation = operationCombobox.getSelectedItem().toString();
if (operation.equals("ALL")) {
operation = null;
}
dateFormatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
startdate = startDate == null ? "" : dateFormatter.format(startDate);
enddate = endDate == null ? "" : dateFormatter.format(endDate);

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String startdate = formatter.format(start_cal.getTime());
String enddate = formatter.format(end_cal.getTime());

History query = new History();
query.setQueryArgs(startdate, enddate, username, code, operation);

tableModel.setHistoryList(query);
tableModel.fireTableDataChanged();

/*} else if (e.getSource() == refresh ) {
System.out.println("##### Refresh button pressed.");
tableModel.refreshHistoryList();
tableModel.fireTableDataChanged();*/

} else if (e.getSource() == export ) {
//System.out.println("##### Export button pressed.");
List<History> hisList = tableModel.getHistoryList();
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/update.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name=EVS History
id=evs-history
version=1.0.5
download=https://github.com/ncievs/evs-history/releases/download/evs-history-1.0.5/evs-history-1.0.5-SNAPSHOT.jar
version=1.0.6
download=https://github.com/ncievs/evs-history/releases/download/evs-history-1.0.6/evs-history-1.0.6-SNAPSHOT.jar
readme=https://raw.githubusercontent.com/ncievs/evs-history/master/src/main/resources/readme.html
license=http://www.gnu.org/licenses/lgpl.html
author=Bob Dionne
Expand Down

0 comments on commit 0789938

Please sign in to comment.