Save the current comment to prevent having to return null if the user cancels.

Fix a few deprecated function calls.
This commit is contained in:
Ann Priestman 2018-06-15 11:25:33 -04:00
parent 0766f645a6
commit 1cf2028d87
5 changed files with 20 additions and 15 deletions

View File

@ -84,9 +84,10 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
* exists there, or a new file instance will be added to the database with * exists there, or a new file instance will be added to the database with
* the comment attached otherwise. * the comment attached otherwise.
* *
* The new comment is returned in case it is needed to update the display * The current comment for this instance is returned in case it is needed to
* update the display.
* *
* @return the newly added comment or null if it was not updated * @return the current comment for this instance
*/ */
public String addEditCentralRepoComment() { public String addEditCentralRepoComment() {
CentralRepoCommentDialog centralRepoCommentDialog = new CentralRepoCommentDialog(correlationAttribute, title); CentralRepoCommentDialog centralRepoCommentDialog = new CentralRepoCommentDialog(correlationAttribute, title);
@ -106,9 +107,8 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
} catch (EamDbException ex) { } catch (EamDbException ex) {
logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex); logger.log(Level.SEVERE, "Error connecting to Central Repository database.", ex);
} }
return centralRepoCommentDialog.getComment();
} }
return null; return centralRepoCommentDialog.getComment();
} }
/** /**

View File

@ -31,7 +31,7 @@ final class CentralRepoCommentDialog extends javax.swing.JDialog {
private final CorrelationAttribute correlationAttribute; private final CorrelationAttribute correlationAttribute;
private boolean commentUpdated = false; private boolean commentUpdated = false;
private String comment = ""; private String currentComment = "";
/** /**
* Create an instance. * Create an instance.
@ -45,6 +45,11 @@ final class CentralRepoCommentDialog extends javax.swing.JDialog {
initComponents(); initComponents();
CorrelationAttributeInstance instance = correlationAttribute.getInstances().get(0); CorrelationAttributeInstance instance = correlationAttribute.getInstances().get(0);
// Store the original comment
if (instance.getComment() != null) {
currentComment = instance.getComment();
}
pathLabel.setText(instance.getFilePath()); pathLabel.setText(instance.getFilePath());
commentTextArea.setText(instance.getComment()); commentTextArea.setText(instance.getComment());
@ -74,11 +79,13 @@ final class CentralRepoCommentDialog extends javax.swing.JDialog {
} }
/** /**
* Get the newly added comment * Get the current comment.
* If the user hit OK, this will be the new comment.
* If the user canceled, this will be the original comment.
* @return the comment * @return the comment
*/ */
String getComment() { String getComment() {
return comment; return currentComment;
} }
/** /**
@ -177,8 +184,8 @@ final class CentralRepoCommentDialog extends javax.swing.JDialog {
}//GEN-LAST:event_cancelButtonActionPerformed }//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
comment = commentTextArea.getText(); currentComment = commentTextArea.getText();
correlationAttribute.getInstances().get(0).setComment(comment); correlationAttribute.getInstances().get(0).setComment(currentComment);
commentUpdated = true; commentUpdated = true;
dispose(); dispose();

View File

@ -120,10 +120,8 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi
try { try {
OtherOccurrenceNodeData selectedNode = (OtherOccurrenceNodeData) tableModel.getRow(otherCasesTable.getSelectedRow()); OtherOccurrenceNodeData selectedNode = (OtherOccurrenceNodeData) tableModel.getRow(otherCasesTable.getSelectedRow());
AddEditCentralRepoCommentAction action = AddEditCentralRepoCommentAction.createAddEditCommentAction(selectedNode.createCorrelationAttribute()); AddEditCentralRepoCommentAction action = AddEditCentralRepoCommentAction.createAddEditCommentAction(selectedNode.createCorrelationAttribute());
String newComment = action.addEditCentralRepoComment(); String currentComment = action.addEditCentralRepoComment();
if (newComment != null) { selectedNode.updateComment(currentComment);
selectedNode.updateComment(newComment);
}
otherCasesTable.repaint(); otherCasesTable.repaint();
} catch (EamDbException ex) { } catch (EamDbException ex) {
logger.log(Level.SEVERE, "Error performing Add/Edit Comment action", ex); logger.log(Level.SEVERE, "Error performing Add/Edit Comment action", ex);

View File

@ -1772,7 +1772,7 @@ abstract class AbstractSqlEamDb implements EamDb {
} catch (SQLException ex) { } catch (SQLException ex) {
throw new EamDbException("Error getting all artifact instances from instances table", ex); throw new EamDbException("Error getting all artifact instances from instances table", ex);
} finally { } finally {
EamDbUtil.closePreparedStatement(preparedStatement); EamDbUtil.closeStatement(preparedStatement);
EamDbUtil.closeResultSet(resultSet); EamDbUtil.closeResultSet(resultSet);
EamDbUtil.closeConnection(conn); EamDbUtil.closeConnection(conn);
} }

View File

@ -221,7 +221,7 @@ public final class PostgresEamDbSettings {
LOGGER.log(Level.SEVERE, "Failed to execute database existance query.", ex); // NON-NLS LOGGER.log(Level.SEVERE, "Failed to execute database existance query.", ex); // NON-NLS
return false; return false;
} finally { } finally {
EamDbUtil.closePreparedStatement(ps); EamDbUtil.closeStatement(ps);
EamDbUtil.closeResultSet(rs); EamDbUtil.closeResultSet(rs);
EamDbUtil.closeConnection(conn); EamDbUtil.closeConnection(conn);
} }