From 078993809c0a79c673b97b467de43b977cb6d0f5 Mon Sep 17 00:00:00 2001 From: Bob Dionne Date: Mon, 27 Feb 2023 12:49:48 -0500 Subject: [PATCH] Upgrade 3rd party jpicker to fix null pointer on linux --- pom.xml | 4 +- .../java/gov/nih/nci/evs/EVSHistoryPanel.java | 100 +++++++----------- src/main/resources/update.properties | 4 +- 3 files changed, 43 insertions(+), 65 deletions(-) diff --git a/pom.xml b/pom.xml index ec115c9..b457967 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ gov.nih.nci evs-history - 1.0.5-SNAPSHOT + 1.0.6-SNAPSHOT bundle EVS History Plugin @@ -58,7 +58,7 @@ org.jdatepicker jdatepicker - 1.3.4 + 2.0.0-SNAPSHOT diff --git a/src/main/java/gov/nih/nci/evs/EVSHistoryPanel.java b/src/main/java/gov/nih/nci/evs/EVSHistoryPanel.java index 64ae056..8536e13 100644 --- a/src/main/java/gov/nih/nci/evs/EVSHistoryPanel.java +++ b/src/main/java/gov/nih/nci/evs/EVSHistoryPanel.java @@ -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; @@ -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; @@ -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; @@ -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; @@ -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}; @@ -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)); @@ -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); @@ -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; } @@ -259,7 +250,6 @@ public void populateEVSHistoryTable( ) { } public void setSelectedClass(OWLClass cls) { - selected = cls; } public void disposeView() { @@ -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 hisList = tableModel.getHistoryList(); diff --git a/src/main/resources/update.properties b/src/main/resources/update.properties index 6329a67..0eb65e4 100644 --- a/src/main/resources/update.properties +++ b/src/main/resources/update.properties @@ -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