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
* 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() {
CentralRepoCommentDialog centralRepoCommentDialog = new CentralRepoCommentDialog(correlationAttribute, title);
@ -106,9 +107,8 @@ public final class AddEditCentralRepoCommentAction extends AbstractAction {
} catch (EamDbException 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 boolean commentUpdated = false;
private String comment = "";
private String currentComment = "";
/**
* Create an instance.
@ -46,6 +46,11 @@ final class CentralRepoCommentDialog extends javax.swing.JDialog {
CorrelationAttributeInstance instance = correlationAttribute.getInstances().get(0);
// Store the original comment
if (instance.getComment() != null) {
currentComment = instance.getComment();
}
pathLabel.setText(instance.getFilePath());
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
*/
String getComment() {
return comment;
return currentComment;
}
/**
@ -177,8 +184,8 @@ final class CentralRepoCommentDialog extends javax.swing.JDialog {
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_okButtonActionPerformed
comment = commentTextArea.getText();
correlationAttribute.getInstances().get(0).setComment(comment);
currentComment = commentTextArea.getText();
correlationAttribute.getInstances().get(0).setComment(currentComment);
commentUpdated = true;
dispose();

View File

@ -120,10 +120,8 @@ public class DataContentViewerOtherCases extends JPanel implements DataContentVi
try {
OtherOccurrenceNodeData selectedNode = (OtherOccurrenceNodeData) tableModel.getRow(otherCasesTable.getSelectedRow());
AddEditCentralRepoCommentAction action = AddEditCentralRepoCommentAction.createAddEditCommentAction(selectedNode.createCorrelationAttribute());
String newComment = action.addEditCentralRepoComment();
if (newComment != null) {
selectedNode.updateComment(newComment);
}
String currentComment = action.addEditCentralRepoComment();
selectedNode.updateComment(currentComment);
otherCasesTable.repaint();
} catch (EamDbException 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) {
throw new EamDbException("Error getting all artifact instances from instances table", ex);
} finally {
EamDbUtil.closePreparedStatement(preparedStatement);
EamDbUtil.closeStatement(preparedStatement);
EamDbUtil.closeResultSet(resultSet);
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
return false;
} finally {
EamDbUtil.closePreparedStatement(ps);
EamDbUtil.closeStatement(ps);
EamDbUtil.closeResultSet(rs);
EamDbUtil.closeConnection(conn);
}