/* 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.operation.OperationViewRevision;
import com.qumasoft.qvcslib.LogfileInfo;
import com.qumasoft.qvcslib.MergedInfoInterface;
import com.qumasoft.qvcslib.RevisionInformation;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
/**
* View revision dialog.
* @author Jim Voris
*/
public class ViewRevisionDialog extends AbstractQWinCommandDialog implements ListSelectionListener {
private static final long serialVersionUID = 1L;
private final List<MergedInfoInterface> selectedFiles;
private OperationViewRevision operationViewRevision = null;
private String selectedRevision = null;
/**
* Creates new form ViewRevisionDialog.
* @param parent the parent frame.
* @param selFiles the list of selected files.
* @param opViewRevision the operation that displayed this dialog.
*/
public ViewRevisionDialog(java.awt.Frame parent, List<MergedInfoInterface> selFiles, OperationViewRevision opViewRevision) {
super(parent, false);
selectedFiles = selFiles;
operationViewRevision = opViewRevision;
initComponents();
populateComponents();
getRootPane().setDefaultButton(viewRevisionButton);
revisionsList.requestFocusInWindow();
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() {
revisionsToViewLabel = new javax.swing.JLabel();
viewRevisionButton = new javax.swing.JButton();
closeButton = new javax.swing.JButton();
revisionListScrollPane = new javax.swing.JScrollPane();
revisionsList = new javax.swing.JList();
setTitle("View Revision");
setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
setResizable(false);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
revisionsToViewLabel.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
revisionsToViewLabel.setLabelFor(revisionListScrollPane);
revisionsToViewLabel.setText("Revision to view:");
viewRevisionButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
viewRevisionButton.setText("View Revision");
viewRevisionButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
viewRevisionButtonActionPerformed(evt);
}
});
closeButton.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
closeButton.setText("Close");
closeButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeButtonActionPerformed(evt);
}
});
revisionsList.setFont(new java.awt.Font("Arial", 0, 12)); // NOI18N
revisionsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
revisionListScrollPane.setViewportView(revisionsList);
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(12, 12, 12)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(revisionsToViewLabel)
.add(revisionListScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 360, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(layout.createSequentialGroup()
.add(viewRevisionButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(18, 18, 18)
.add(closeButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 170, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
.add(12, 12, 12))
);
layout.setVerticalGroup(
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
.add(layout.createSequentialGroup()
.add(12, 12, 12)
.add(revisionsToViewLabel)
.add(4, 4, 4)
.add(revisionListScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 110, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
.add(10, 10, 10)
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
.add(viewRevisionButton)
.add(closeButton))
.addContainerGap(13, Short.MAX_VALUE))
);
pack();
}// </editor-fold>//GEN-END:initComponents
private void viewRevisionButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_viewRevisionButtonActionPerformed
{//GEN-HEADEREND:event_viewRevisionButtonActionPerformed
operationViewRevision.processDialogResult(selectedFiles, this);
}//GEN-LAST:event_viewRevisionButtonActionPerformed
private void closeButtonActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_closeButtonActionPerformed
{//GEN-HEADEREND:event_closeButtonActionPerformed
closeDialog(null);
}//GEN-LAST:event_closeButtonActionPerformed
/** 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() {
closeButtonActionPerformed(null);
}
private void populateComponents() {
viewRevisionButton.setEnabled(false);
revisionsList.addListSelectionListener(this);
if (selectedFiles.size() == 1) {
RevisionsListModel model = new RevisionsListModel();
model.populateModel(selectedFiles.get(0));
revisionsList.setModel(model);
} else if (selectedFiles.size() > 1) {
// We should never have gotten here in the first place.
closeDialog(null);
}
}
/**
* Called whenever the value of the selection changes.
*
* @param e the event that characterizes the change.
*
*/
@Override
public void valueChanged(ListSelectionEvent e) {
int selectedIndex = revisionsList.getSelectedIndex();
if (selectedIndex == -1) {
viewRevisionButton.setEnabled(false);
} else {
viewRevisionButton.setEnabled(true);
}
selectedRevision = (String) revisionsList.getSelectedValue();
}
public String getSelectedRevision() {
return selectedRevision;
}
static class RevisionsListModel extends DefaultListModel<String> {
private static final long serialVersionUID = 1L;
void populateModel(MergedInfoInterface mergedInfo) {
// Populate the list of revisions...
LogfileInfo logfileInfo = mergedInfo.getLogfileInfo();
RevisionInformation revisionInformation = logfileInfo.getRevisionInformation();
for (int i = 0; i < logfileInfo.getLogFileHeaderInfo().getRevisionCount(); i++) {
addElement(revisionInformation.getRevisionHeader(i).getRevisionString());
}
}
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton closeButton;
private javax.swing.JScrollPane revisionListScrollPane;
private javax.swing.JList revisionsList;
private javax.swing.JLabel revisionsToViewLabel;
private javax.swing.JButton viewRevisionButton;
// End of variables declaration//GEN-END:variables
}