28 package org.nexusformat.nxvalidate;
31 import java.io.FileNotFoundException;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.ResourceBundle;
35 import java.util.logging.Level;
36 import java.util.logging.Logger;
37 import javax.swing.table.DefaultTableModel;
45 private File nxdlFile = null;
46 private ArrayList<String> dataFileList = null;
48 private boolean badFiles =
false;
49 private ResourceBundle bundle = null;
50 private ArrayList<String> dataFileSelectedList = null;
56 this.fileLoadingActions = fileLoadingActions;
57 bundle = ResourceBundle.getBundle(
58 "org/nexusformat/nxvalidate/resources/nxvalidate");
65 bundle = ResourceBundle.getBundle(
66 "org/nexusformat/nxvalidate/resources/nxvalidate");
75 @SuppressWarnings(
"unchecked")
77 private
void initComponents() {
79 jFileChooser1 =
new javax.swing.JFileChooser();
80 problemOptionPane =
new javax.swing.JOptionPane();
81 jSplitPane1 =
new javax.swing.JSplitPane();
82 jPanel1 =
new javax.swing.JPanel();
83 loadNXDCButton =
new javax.swing.JButton();
84 loadDataFilesButton =
new javax.swing.JButton();
85 nxdcFileNameTextField =
new javax.swing.JTextField();
86 validateButton =
new javax.swing.JButton();
87 cancelButton =
new javax.swing.JButton();
88 jCheckBox1 =
new javax.swing.JCheckBox();
89 jScrollPane1 =
new javax.swing.JScrollPane();
90 jTable1 =
new javax.swing.JTable();
92 jSplitPane1.setOrientation(javax.swing.JSplitPane.VERTICAL_SPLIT);
94 jPanel1.setVerifyInputWhenFocusTarget(
false);
96 loadNXDCButton.setText(
"Load NXDL");
97 loadNXDCButton.setActionCommand(
"Load NXDL");
98 loadNXDCButton.addActionListener(
new java.awt.event.ActionListener() {
99 public void actionPerformed(java.awt.event.ActionEvent evt) {
100 loadNXDCButtonActionPerformed(evt);
104 loadDataFilesButton.setText(
"Load Data Files");
105 loadDataFilesButton.addActionListener(
new java.awt.event.ActionListener() {
106 public void actionPerformed(java.awt.event.ActionEvent evt) {
107 loadDataFilesButtonActionPerformed(evt);
111 validateButton.setLabel(
"Validate");
112 validateButton.addActionListener(
new java.awt.event.ActionListener() {
113 public void actionPerformed(java.awt.event.ActionEvent evt) {
114 validateButtonActionPerformed(evt);
118 cancelButton.setText(
"Cancel");
119 cancelButton.addActionListener(
new java.awt.event.ActionListener() {
120 public void actionPerformed(java.awt.event.ActionEvent evt) {
121 cancelButtonActionPerformed(evt);
125 jCheckBox1.setText(
"Load files only.");
126 jCheckBox1.setToolTipText(
"Load files only, do not validate.");
127 jCheckBox1.addActionListener(
new java.awt.event.ActionListener() {
128 public void actionPerformed(java.awt.event.ActionEvent evt) {
129 jCheckBox1ActionPerformed(evt);
133 javax.swing.GroupLayout jPanel1Layout =
new javax.swing.GroupLayout(jPanel1);
134 jPanel1.setLayout(jPanel1Layout);
135 jPanel1Layout.setHorizontalGroup(
136 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
137 .addGroup(jPanel1Layout.createSequentialGroup()
139 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING,
false)
140 .addGroup(jPanel1Layout.createSequentialGroup()
141 .addComponent(loadNXDCButton)
142 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
143 .addComponent(nxdcFileNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 549, javax.swing.GroupLayout.PREFERRED_SIZE))
144 .addGroup(jPanel1Layout.createSequentialGroup()
145 .addComponent(loadDataFilesButton)
147 .addComponent(jCheckBox1)
148 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
149 .addComponent(cancelButton)
151 .addComponent(validateButton)))
152 .addContainerGap(17, Short.MAX_VALUE))
154 jPanel1Layout.setVerticalGroup(
155 jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
156 .addGroup(jPanel1Layout.createSequentialGroup()
158 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
159 .addComponent(loadNXDCButton)
160 .addComponent(nxdcFileNameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
162 .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
163 .addComponent(loadDataFilesButton)
164 .addComponent(validateButton)
165 .addComponent(cancelButton)
166 .addComponent(jCheckBox1))
167 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
170 jSplitPane1.setTopComponent(jPanel1);
172 jTable1.setModel(
new javax.swing.table.DefaultTableModel(
177 "Include",
"File Name"
180 Class[] types =
new Class [] {
181 java.lang.Boolean.class, java.lang.String.class
184 public Class getColumnClass(
int columnIndex) {
185 return types [columnIndex];
188 jScrollPane1.setViewportView(jTable1);
189 jTable1.getColumnModel().getColumn(0).setMinWidth(60);
190 jTable1.getColumnModel().getColumn(0).setPreferredWidth(60);
191 jTable1.getColumnModel().getColumn(0).setMaxWidth(60);
193 jSplitPane1.setRightComponent(jScrollPane1);
195 javax.swing.GroupLayout layout =
new javax.swing.GroupLayout(getContentPane());
196 getContentPane().setLayout(layout);
197 layout.setHorizontalGroup(
198 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
199 .addComponent(jSplitPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 672, Short.MAX_VALUE)
201 layout.setVerticalGroup(
202 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
203 .addComponent(jSplitPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 534, Short.MAX_VALUE)
209 private void loadNXDCButtonActionPerformed(java.awt.event.ActionEvent evt) {
210 if (evt.getSource() == loadNXDCButton) {
212 jFileChooser1.setMultiSelectionEnabled(
false);
213 jFileChooser1.setFileSelectionMode(jFileChooser1.FILES_ONLY);
214 int returnVal = jFileChooser1.showOpenDialog(
this);
216 if (returnVal == jFileChooser1.APPROVE_OPTION) {
217 nxdlFile = jFileChooser1.getSelectedFile();
219 if(check.checkNXDLFile(nxdlFile)){
221 nxdcFileNameTextField.setText(nxdlFile.getAbsolutePath());
222 nxdcFileNameTextField.setToolTipText(nxdlFile.getAbsolutePath());
226 problemOptionPane.showMessageDialog(
this,
227 bundle.getString(
"notNXDLFileMessage"));
238 private void loadDataFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {
239 if (evt.getSource() == loadDataFilesButton) {
241 dataFileList =
new ArrayList<String>();
243 File[] dataFiles = null;
244 jFileChooser1.setMultiSelectionEnabled(
true);
245 jFileChooser1.setFileSelectionMode(jFileChooser1.FILES_AND_DIRECTORIES);
246 int returnVal = jFileChooser1.showOpenDialog(
this);
248 if (returnVal == jFileChooser1.APPROVE_OPTION) {
250 dataFiles = jFileChooser1.getSelectedFiles();
251 fileLoadingActions.setDataFiles(dataFiles);
252 fileLoadingActions.setWhich(3);
253 fileLoadingActions.bulkCheck();
254 dataFileList = fileLoadingActions.getDataFileList();
256 }
catch (FileNotFoundException ex) {
257 Logger.getLogger(BulkLoadFilesFrame.class.getName()).log(Level.SEVERE, null, ex);
258 }
catch (IOException ex) {
259 Logger.getLogger(BulkLoadFilesFrame.class.getName()).log(Level.SEVERE, null, ex);
268 private void updateTable() throws FileNotFoundException, IOException {
270 DefaultTableModel tableModel =
new DefaultTableModel(
new Object[][]{
274 "Include",
"File Name"
277 Class[] types =
new Class[]{
278 java.lang.Boolean.class, java.lang.String.class
281 public Class getColumnClass(
int columnIndex) {
282 return types[columnIndex];
286 tableModel.removeRow(0);
288 Boolean useIt =
new Boolean(
true);
289 Object[] row =
new Object[2];
290 for (
int i = 0; i < dataFileList.size(); ++i) {
291 row[1] = dataFileList.get(i);
292 if (check.checkNexusFile(
new File(dataFileList.get(i)))) {
293 row[0] =
new Boolean(
true);
295 row[0] =
new Boolean(
false);
299 tableModel.addRow(row);
302 jTable1.setModel(tableModel);
303 jTable1.getColumnModel().getColumn(0).setMinWidth(60);
304 jTable1.getColumnModel().getColumn(0).setPreferredWidth(60);
305 jTable1.getColumnModel().getColumn(0).setMaxWidth(60);
308 problemOptionPane.showMessageDialog(
this,
309 bundle.getString(
"filesNotNexusError"));
314 private void validateButtonActionPerformed(java.awt.event.ActionEvent evt) {
316 if (evt.getSource() == validateButton) {
318 if (nxdlFile == null) {
319 problemOptionPane.showMessageDialog(
this,
320 bundle.getString(
"openSchemaFileMessage"));
324 if (fileLoadingActions.getNXConvertFile() == null) {
325 problemOptionPane.showMessageDialog(
this,
326 bundle.getString(
"noConvertCommandFound"));
331 Boolean checked = null;
332 dataFileSelectedList =
new ArrayList<String>();
334 int rows = jTable1.getModel().getRowCount();
336 for (
int i = 0; i < rows; ++i) {
337 checked = (Boolean) jTable1.getModel().getValueAt(i, 0);
340 dataFileSelectedList.add((String) jTable1.getModel().getValueAt(i, 1));
345 if (jCheckBox1.isSelected()) {
347 fileLoadingActions.setWhich(4);
348 fileLoadingActions.setNXDLFile(nxdlFile);
349 fileLoadingActions.setDataFileList(dataFileSelectedList);
351 (
new Thread(fileLoadingActions)).start();
355 fileLoadingActions.setWhich(5);
356 fileLoadingActions.setNXDLFile(nxdlFile);
357 fileLoadingActions.setDataFileList(dataFileSelectedList);
359 (
new Thread(fileLoadingActions)).start();
365 private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {
367 if (evt.getSource() == jCheckBox1) {
369 if (jCheckBox1.isSelected()) {
370 validateButton.setText(
"Load");
372 validateButton.setText(
"Validate");
378 private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {
379 if (evt.getSource() == cancelButton) {
380 this.setVisible(
false);
387 public static void main(String args[]) {
388 java.awt.EventQueue.invokeLater(
new Runnable() {
396 private javax.swing.JButton cancelButton;
397 private javax.swing.JCheckBox jCheckBox1;
398 private javax.swing.JFileChooser jFileChooser1;
399 private javax.swing.JPanel jPanel1;
400 private javax.swing.JScrollPane jScrollPane1;
401 private javax.swing.JSplitPane jSplitPane1;
402 private javax.swing.JTable jTable1;
403 private javax.swing.JButton loadDataFilesButton;
404 private javax.swing.JButton loadNXDCButton;
405 private javax.swing.JTextField nxdcFileNameTextField;
406 private javax.swing.JOptionPane problemOptionPane;
407 private javax.swing.JButton validateButton;