/* Copyright 2004-2014 Jim Voris
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.qumasoft.guitools.qwin.dialog;
import com.qumasoft.guitools.qwin.QWinFrame;
import com.qumasoft.guitools.qwin.operation.OperationSetRevisionDescription;
import com.qumasoft.qvcslib.CheckInCommentProperties;
import com.qumasoft.qvcslib.MergedInfoInterface;
import com.qumasoft.qvcslib.QVCSConstants;
import java.util.List;
/**
* Set revision description dialog.
* @author Jim Voris
*/
public final class SetRevisionDescriptionDialog extends AbstractQWinCommandDialog {
private static final long serialVersionUID = 2952240364586194400L;
private boolean isOKFlag = false;
private int checkInCommentIndex = 0;
private final QWinFrame parentFrame;
private final List selectedFiles;
private String revisionString;
private final MergedInfoInterface mergedInfo;
private final CheckInCommentProperties checkInCommentProperties;
private final OperationSetRevisionDescription operationSetRevisionDescription;
/**
* Create a set revision description dialog.
* @param parent the parent frame.
* @param files the selected files.
* @param checkInComments checkin comments.
* @param operation the operation that will do the work.
*/
public SetRevisionDescriptionDialog(java.awt.Frame parent, List files, CheckInCommentProperties checkInComments,
OperationSetRevisionDescription operation) {
super(parent, true);
this.selectedFiles = files;
this.parentFrame = (QWinFrame) parent;
this.mergedInfo = (MergedInfoInterface) selectedFiles.get(0);
this.operationSetRevisionDescription = operation;
this.checkInCommentProperties = checkInComments;
initComponents();
populateComponents();
getRootPane().setDefaultButton(okButton);
setFont();
center();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
revisionLabel = new javax.swing.JLabel();
revisionComboBox = new javax.swing.JComboBox();
okButton = new javax.swing.JButton();
cancelButton = new javax.swing.JButton();
nextButton = new javax.swing.JButton();
prevButton = new javax.swing.JButton();
clearButton = new javax.swing.JButton();
existingRevisionDescriptionLabel = new javax.swing.JLabel();
existingRevisionDescriptionScrollPane = new javax.swing.JScrollPane();
existingRevisionDescriptionTextArea = new javax.swing.JTextArea();
newRevisionDescriptionLabel = new javax.swing.JLabel();
newRevisionDescriptionScrollPane = new javax.swing.JScrollPane();
m_NewRevisionDescriptionTextArea = new javax.swing.JTextArea();
setTitle("Set Revision Description");
setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
setName("CheckIn"); // NOI18N
setResizable(false);
revisionLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
revisionLabel.setLabelFor(revisionComboBox);
revisionLabel.setText("Select a revision to change its description:");
revisionComboBox.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
revisionComboBox.setMaximumRowCount(10);
revisionComboBox.setToolTipText("Select the revision to get");
revisionComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
revisionComboBoxActionPerformed(evt);
}
});
okButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
okButton.setText(" OK ");
okButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
okButtonActionPerformed(evt);
}
});
cancelButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
cancelButton.setText("Cancel");
cancelButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cancelButtonActionPerformed(evt);
}
});
nextButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
nextButton.setMnemonic('x');
nextButton.setText("Next");
nextButton.setToolTipText("Next CheckIn Comment");
nextButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
nextButtonActionPerformed(evt);
}
});
prevButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
prevButton.setMnemonic('v');
prevButton.setText("Prev");
prevButton.setToolTipText("Previous CheckIn Comment");
prevButton.setEnabled(false);
prevButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
prevButtonActionPerformed(evt);
}
});
clearButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
clearButton.setText("Clear");
clearButton.setToolTipText("Clear CheckIn Comment");
clearButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
clearButtonActionPerformed(evt);
}
});
existingRevisionDescriptionLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
existingRevisionDescriptionLabel.setLabelFor(existingRevisionDescriptionTextArea);
existingRevisionDescriptionLabel.setText("Existing Revision Description:");
existingRevisionDescriptionScrollPane.setAutoscrolls(true);
existingRevisionDescriptionScrollPane.setDoubleBuffered(true);
existingRevisionDescriptionTextArea.setEditable(false);
existingRevisionDescriptionTextArea.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
existingRevisionDescriptionTextArea.setLineWrap(true);
existingRevisionDescriptionTextArea.setRows(10);
existingRevisionDescriptionTextArea.setTabSize(4);
existingRevisionDescriptionTextArea.setWrapStyleWord(true);
existingRevisionDescriptionTextArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
existingRevisionDescriptionTextArea.setDoubleBuffered(true);
existingRevisionDescriptionTextArea.setMaximumSize(new java.awt.Dimension(102, 120));
existingRevisionDescriptionTextArea.setMinimumSize(new java.awt.Dimension(102, 120));
existingRevisionDescriptionScrollPane.setViewportView(existingRevisionDescriptionTextArea);
newRevisionDescriptionLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
newRevisionDescriptionLabel.setLabelFor(m_NewRevisionDescriptionTextArea);
newRevisionDescriptionLabel.setText("New Revision Description:");
newRevisionDescriptionScrollPane.setAutoscrolls(true);
newRevisionDescriptionScrollPane.setDoubleBuffered(true);
m_NewRevisionDescriptionTextArea.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
m_NewRevisionDescriptionTextArea.setLineWrap(true);
m_NewRevisionDescriptionTextArea.setRows(10);
m_NewRevisionDescriptionTextArea.setTabSize(4);
m_NewRevisionDescriptionTextArea.setWrapStyleWord(true);
m_NewRevisionDescriptionTextArea.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
m_NewRevisionDescriptionTextArea.setDoubleBuffered(true);
m_NewRevisionDescriptionTextArea.setMaximumSize(new java.awt.Dimension(102, 120));
m_NewRevisionDescriptionTextArea.setMinimumSize(new java.awt.Dimension(102, 120));
newRevisionDescriptionScrollPane.setViewportView(m_NewRevisionDescriptionTextArea);
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(10, 10, 10)
.add(revisionLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(12, 12, 12)
.add(revisionComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(10, 10, 10)
.add(existingRevisionDescriptionLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(10, 10, 10)
.add(existingRevisionDescriptionScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(10, 10, 10)
.add(newRevisionDescriptionLabel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(10, 10, 10)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 174, Short.MAX_VALUE)
.add(cancelButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(layout.createSequentialGroup()
.add(newRevisionDescriptionScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 14, Short.MAX_VALUE))))
.add(org.jdesktop.layout.GroupLayout.LEADING, layout.createSequentialGroup()
.add(120, 120, 120)
.add(nextButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(0, 0, 0)
.add(prevButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(10, 10, 10)
.add(clearButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 80, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
.addContainerGap(9, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(10, 10, 10)
.add(revisionLabel)
.add(6, 6, 6)
.add(revisionComboBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(3, 3, 3)
.add(existingRevisionDescriptionLabel)
.add(6, 6, 6)
.add(existingRevisionDescriptionScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(10, 10, 10)
.add(newRevisionDescriptionLabel)
.add(6, 6, 6)
.add(newRevisionDescriptionScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 100, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(nextButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(prevButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(clearButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 20, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
.add(20, 20, 20)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(okButton)
.add(cancelButton))
.add(13, 13, 13))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void revisionComboBoxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_revisionComboBoxActionPerformed
{//GEN-HEADEREND:event_revisionComboBoxActionPerformed
// Update the existing revision description for the selected revision.
String revString = captureRevisionString();
String existingRevisionDescription = mergedInfo.getRevisionDescription(revString);
setExistingRevisionDescription(existingRevisionDescription);
setNewRevisionDescription(existingRevisionDescription);
// Don't allow user to edit any revision description that marks a rename or a move.
if (existingRevisionDescription.startsWith(QVCSConstants.QVCS_INTERNAL_REV_COMMENT_PREFIX)) {
okButton.setEnabled(false);
} else {
okButton.setEnabled(true);
}
m_NewRevisionDescriptionTextArea.requestFocusInWindow();
}//GEN-LAST:event_revisionComboBoxActionPerformed
private void clearButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_clearButtonActionPerformed
{//GEN-HEADEREND:event_clearButtonActionPerformed
// Clear the checkin comment.
setNewRevisionDescription("");
m_NewRevisionDescriptionTextArea.requestFocusInWindow();
}//GEN-LAST:event_clearButtonActionPerformed
private void prevButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_prevButtonActionPerformed
{//GEN-HEADEREND:event_prevButtonActionPerformed
// Display the previous checkin comment.
if (checkInCommentIndex > 0) {
checkInCommentIndex--;
setNewRevisionDescription(checkInCommentProperties.getCheckInComment(checkInCommentIndex));
nextButton.setEnabled(true);
m_NewRevisionDescriptionTextArea.requestFocusInWindow();
}
if (checkInCommentIndex == 0) {
// Disable the next button.
prevButton.setEnabled(false);
}
}//GEN-LAST:event_prevButtonActionPerformed
private void nextButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_nextButtonActionPerformed
{//GEN-HEADEREND:event_nextButtonActionPerformed
// Display the next check-in comment.
int knownComments = checkInCommentProperties.getCommentCount();
if (checkInCommentIndex < (knownComments - 1)) {
checkInCommentIndex++;
setNewRevisionDescription(checkInCommentProperties.getCheckInComment(checkInCommentIndex));
prevButton.setEnabled(true);
m_NewRevisionDescriptionTextArea.requestFocusInWindow();
}
if (checkInCommentIndex == (knownComments - 1)) {
// Disable the next button.
nextButton.setEnabled(false);
}
}//GEN-LAST:event_nextButtonActionPerformed
private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_cancelButtonActionPerformed
{//GEN-HEADEREND:event_cancelButtonActionPerformed
isOKFlag = false;
closeDialog(null);
}//GEN-LAST:event_cancelButtonActionPerformed
private void okButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_okButtonActionPerformed
{//GEN-HEADEREND:event_okButtonActionPerformed
isOKFlag = true;
checkInCommentProperties.addCheckInComment(m_NewRevisionDescriptionTextArea.getText());
closeDialog(null);
operationSetRevisionDescription.processDialogResult(selectedFiles, this);
}//GEN-LAST:event_okButtonActionPerformed
/** Closes the dialog */
private void closeDialog(java.awt.event.WindowEvent evt)
{//GEN-FIRST:event_closeDialog
setVisible(false);
dispose();
}//GEN-LAST:event_closeDialog
@Override
public void dismissDialog() {
cancelButtonActionPerformed(null);
}
private void populateComponents() {
revisionComboBox.setModel(new RevisionsComboModelWithNoDefault(mergedInfo));
revisionComboBoxActionPerformed(null);
}
public void setNewRevisionDescription(String description) {
m_NewRevisionDescriptionTextArea.setText(description);
m_NewRevisionDescriptionTextArea.select(0, description.length());
}
public String getNewRevisionDescription() {
return m_NewRevisionDescriptionTextArea.getText();
}
public void setExistingRevisionDescription(String description) {
existingRevisionDescriptionTextArea.setText(description);
}
public boolean getIsOK() {
return isOKFlag;
}
private String captureRevisionString() {
revisionString = (String) revisionComboBox.getModel().getSelectedItem();
return revisionString;
}
public String getRevisionString() {
return revisionString;
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton cancelButton;
private javax.swing.JButton clearButton;
private javax.swing.JLabel existingRevisionDescriptionLabel;
private javax.swing.JScrollPane existingRevisionDescriptionScrollPane;
private javax.swing.JTextArea existingRevisionDescriptionTextArea;
private javax.swing.JTextArea m_NewRevisionDescriptionTextArea;
private javax.swing.JLabel newRevisionDescriptionLabel;
private javax.swing.JScrollPane newRevisionDescriptionScrollPane;
private javax.swing.JButton nextButton;
private javax.swing.JButton okButton;
private javax.swing.JButton prevButton;
private javax.swing.JComboBox revisionComboBox;
private javax.swing.JLabel revisionLabel;
// End of variables declaration//GEN-END:variables
}