fitnesserefactor.FitnesseRefactor.java Source code

Java tutorial

Introduction

Here is the source code for fitnesserefactor.FitnesseRefactor.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package fitnesserefactor;

import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import javax.swing.text.BadLocationException;
import org.apache.commons.io.FileUtils;

/**
 *
 * @author iselvan
 */
public class FitnesseRefactor extends javax.swing.JFrame {

    /**
     * Creates new form FitnesseRefactor
     */
    public int p;

    public FitnesseRefactor() {
        initComponents();
        setIcon();
    }

    /**
     * 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        PreviewScroll = new javax.swing.JScrollPane();
        PreviewTextArea = new javax.swing.JTextArea();
        JtreeScroll = new javax.swing.JScrollPane();
        jTree1 = new javax.swing.JTree();
        LblPreview = new javax.swing.JLabel();
        TablesList = new javax.swing.JPanel();
        RowField = new javax.swing.JTextField();
        ColumnField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        ParentFolder = new javax.swing.JCheckBox();
        jScrollPane1 = new javax.swing.JScrollPane();
        EditArea = new javax.swing.JTextArea();
        jLabel3 = new javax.swing.JLabel();
        AddColumn = new javax.swing.JButton();
        AddTable = new javax.swing.JButton();
        DelTable = new javax.swing.JButton();
        fromTxt = new javax.swing.JTextField();
        FromLbl = new javax.swing.JLabel();
        ToLbl = new javax.swing.JLabel();
        toTxt = new javax.swing.JTextField();
        deleteColBtn = new javax.swing.JButton();
        btn_SaveFile = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        FindWhatTxt = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        ReplaceWithTxt = new javax.swing.JTextField();
        jTextField5 = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jTextField6 = new javax.swing.JTextField();
        ParentFolder1 = new javax.swing.JCheckBox();
        ReplaceAllBtn = new javax.swing.JButton();
        StartIndexTxt = new javax.swing.JTextField();
        EndIndexTxt = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel9 = new javax.swing.JLabel();
        RowLbl = new javax.swing.JLabel();
        RowNoDisplay = new javax.swing.JLabel();
        ColumnNo = new javax.swing.JLabel();
        ColumnNoDisplay = new javax.swing.JLabel();
        ProgressBar = new javax.swing.JProgressBar();
        jLabel10 = new javax.swing.JLabel();
        Lbl_table = new javax.swing.JLabel();
        FitnesseTablesList = new javax.swing.JComboBox();
        jMenuBar2 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        jMenu4 = new javax.swing.JMenu();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Fitnesse Refactor");
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        PreviewTextArea.setColumns(20);
        PreviewTextArea.setRows(5);
        PreviewTextArea.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                PreviewTextAreaMouseClicked(evt);
            }
        });
        PreviewTextArea.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                PreviewTextAreaKeyPressed(evt);
            }
        });
        PreviewScroll.setViewportView(PreviewTextArea);

        getContentPane().add(PreviewScroll, new org.netbeans.lib.awtextra.AbsoluteConstraints(720, 30, 620, 600));

        jTree1.setModel(new FileSystemModel(new File("C:\\")));
        jTree1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTree1MouseClicked(evt);
            }
        });
        JtreeScroll.setViewportView(jTree1);

        getContentPane().add(JtreeScroll, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 13, 310, 640));

        LblPreview.setText("Preview");
        getContentPane().add(LblPreview, new org.netbeans.lib.awtextra.AbsoluteConstraints(710, 0, -1, -1));

        TablesList.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Table Level",
                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, java.awt.Color.black));

        RowField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                RowFieldActionPerformed(evt);
            }
        });

        ColumnField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ColumnFieldActionPerformed(evt);
            }
        });

        jLabel1.setText("Row No                      :");

        jLabel2.setText("Column No                 :");

        ParentFolder.setText("For all testcases under the parent folder");

        EditArea.setColumns(20);
        EditArea.setRows(5);
        EditArea.setDisabledTextColor(new java.awt.Color(0, 0, 0));
        jScrollPane1.setViewportView(EditArea);

        jLabel3.setText("Value to be added");

        AddColumn.setText("Add Column");
        AddColumn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddColumnActionPerformed(evt);
            }
        });

        AddTable.setText("Add Table");
        AddTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                AddTableActionPerformed(evt);
            }
        });

        DelTable.setText("Delete Table");
        DelTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DelTableActionPerformed(evt);
            }
        });

        fromTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                fromTxtActionPerformed(evt);
            }
        });

        FromLbl.setText("From");

        ToLbl.setText("To");

        toTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toTxtActionPerformed(evt);
            }
        });

        deleteColBtn.setText("Delete Column");
        deleteColBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteColBtnActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout TablesListLayout = new javax.swing.GroupLayout(TablesList);
        TablesList.setLayout(TablesListLayout);
        TablesListLayout.setHorizontalGroup(TablesListLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(TablesListLayout.createSequentialGroup().addGroup(TablesListLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(TablesListLayout.createSequentialGroup().addGap(4, 4, 4)
                                .addComponent(FromLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(fromTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(ToLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(toTxt, javax.swing.GroupLayout.PREFERRED_SIZE, 40,
                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(TablesListLayout.createSequentialGroup().addGap(10, 10, 10)
                                .addComponent(ParentFolder))
                        .addGroup(TablesListLayout.createSequentialGroup().addGap(10, 10, 10).addComponent(jLabel3))
                        .addGroup(TablesListLayout.createSequentialGroup().addGap(10, 10, 10).addComponent(
                                jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 309,
                                javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(TablesListLayout.createSequentialGroup()
                                .addGroup(TablesListLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 128,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(jLabel2))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(TablesListLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(RowField, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(ColumnField, javax.swing.GroupLayout.PREFERRED_SIZE, 45,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGroup(TablesListLayout.createSequentialGroup().addGap(29, 29, 29)
                                .addGroup(TablesListLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(AddColumn, javax.swing.GroupLayout.PREFERRED_SIZE, 114,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(AddTable, javax.swing.GroupLayout.PREFERRED_SIZE, 114,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(36, 36, 36)
                                .addGroup(TablesListLayout
                                        .createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(deleteColBtn, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
                                                javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(DelTable, javax.swing.GroupLayout.PREFERRED_SIZE, 120,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addContainerGap(29, Short.MAX_VALUE)));
        TablesListLayout.setVerticalGroup(TablesListLayout
                .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(TablesListLayout.createSequentialGroup().addContainerGap().addGroup(TablesListLayout
                        .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(jLabel1)
                        .addComponent(RowField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(TablesListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(TablesListLayout.createSequentialGroup()
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(ColumnField, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                javax.swing.GroupLayout.DEFAULT_SIZE,
                                                javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(TablesListLayout.createSequentialGroup().addGap(7, 7, 7)
                                        .addComponent(jLabel2).addGap(18, 18, 18)
                                        .addGroup(TablesListLayout
                                                .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                                .addComponent(fromTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(FromLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(ToLbl, javax.swing.GroupLayout.PREFERRED_SIZE, 30,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addComponent(toTxt, javax.swing.GroupLayout.PREFERRED_SIZE,
                                                        javax.swing.GroupLayout.DEFAULT_SIZE,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))))
                        .addGap(6, 6, 6).addComponent(ParentFolder).addGap(7, 7, 7)
                        .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 17,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(6, 6, 6)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 55,
                                javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9)
                        .addGroup(TablesListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(deleteColBtn).addComponent(AddColumn))
                        .addGap(7, 7, 7)
                        .addGroup(TablesListLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(DelTable).addComponent(AddTable))
                        .addContainerGap(41, Short.MAX_VALUE)));

        getContentPane().add(TablesList, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 50, 360, 340));

        btn_SaveFile.setText("Save");
        btn_SaveFile.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SaveFileActionPerformed(evt);
            }
        });
        getContentPane().add(btn_SaveFile, new org.netbeans.lib.awtextra.AbsoluteConstraints(960, 640, 100, 30));

        jPanel1.setBorder(javax.swing.BorderFactory
                .createTitledBorder(javax.swing.BorderFactory.createTitledBorder(""), "Find and Replace"));
        jPanel1.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel4.setText("Find what        :");
        jPanel1.add(jLabel4, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 30, -1, 20));

        FindWhatTxt.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FindWhatTxtActionPerformed(evt);
            }
        });
        jPanel1.add(FindWhatTxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 30, 222, -1));

        jLabel5.setText("Replace with   :");
        jPanel1.add(jLabel5, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 60, -1, -1));
        jPanel1.add(ReplaceWithTxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(100, 60, 222, -1));
        jPanel1.add(jTextField5, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 100, 38, -1));

        jLabel6.setText("From Row No. :");
        jPanel1.add(jLabel6, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 100, -1, 20));

        jLabel7.setText("To Row No  ");
        jPanel1.add(jLabel7, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 100, -1, 20));
        jPanel1.add(jTextField6, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 100, 38, -1));

        ParentFolder1.setText("For all test cases under the parent folder");
        ParentFolder1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ParentFolder1ActionPerformed(evt);
            }
        });
        jPanel1.add(ParentFolder1, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 160, -1, -1));

        ReplaceAllBtn.setText("Replace all");
        ReplaceAllBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ReplaceAllBtnActionPerformed(evt);
            }
        });
        jPanel1.add(ReplaceAllBtn, new org.netbeans.lib.awtextra.AbsoluteConstraints(110, 190, 100, -1));
        jPanel1.add(StartIndexTxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(90, 130, 38, -1));
        jPanel1.add(EndIndexTxt, new org.netbeans.lib.awtextra.AbsoluteConstraints(210, 130, 38, -1));

        jLabel8.setText("Start Index     :");
        jPanel1.add(jLabel8, new org.netbeans.lib.awtextra.AbsoluteConstraints(10, 130, -1, -1));

        jLabel9.setText("End Index  ");
        jPanel1.add(jLabel9, new org.netbeans.lib.awtextra.AbsoluteConstraints(140, 130, -1, 20));

        getContentPane().add(jPanel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 400, 360, 230));

        RowLbl.setText("Row No: ");
        getContentPane().add(RowLbl, new org.netbeans.lib.awtextra.AbsoluteConstraints(760, 0, -1, -1));

        RowNoDisplay.setText("0");
        getContentPane().add(RowNoDisplay, new org.netbeans.lib.awtextra.AbsoluteConstraints(810, 0, -1, -1));

        ColumnNo.setText("Column No:");
        getContentPane().add(ColumnNo, new org.netbeans.lib.awtextra.AbsoluteConstraints(830, 0, -1, -1));

        ColumnNoDisplay.setText("0");
        ColumnNoDisplay.setToolTipText("");
        getContentPane().add(ColumnNoDisplay, new org.netbeans.lib.awtextra.AbsoluteConstraints(900, 0, -1, -1));
        getContentPane().add(ProgressBar, new org.netbeans.lib.awtextra.AbsoluteConstraints(410, 640, 280, 20));

        jLabel10.setText("Progress    :");
        getContentPane().add(jLabel10, new org.netbeans.lib.awtextra.AbsoluteConstraints(340, 640, -1, -1));

        Lbl_table.setText("Selet table to modify :");
        getContentPane().add(Lbl_table, new org.netbeans.lib.awtextra.AbsoluteConstraints(350, 20, 128, -1));

        FitnesseTablesList.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                FitnesseTablesListActionPerformed(evt);
            }
        });
        getContentPane().add(FitnesseTablesList,
                new org.netbeans.lib.awtextra.AbsoluteConstraints(470, 20, 199, -1));

        jMenu3.setText("File");
        jMenuBar2.add(jMenu3);

        jMenu4.setText("Edit");
        jMenuBar2.add(jMenu4);

        setJMenuBar(jMenuBar2);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTree1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTree1MouseClicked

        try {
            JtreePath = jTree1.getSelectionPath().toString().replaceAll("[\\[\\]]", "").replace(", ", "\\");
            FitnesseTablesList.removeAllItems();
            FitnesseTablesList.addItem("Select an item");
            FileReader fr = new FileReader(JtreePath);
            BufferedReader textReader = new BufferedReader(fr);
            PreviewTextArea.read(textReader, null);
        } catch (Exception e) {

        }
        String[] lines = PreviewTextArea.getText().split("\\n");
        int totLines = PreviewTextArea.getLineCount();
        for (int i = 0; i < totLines; i++) {
            if (lines[i].toString().contains("!|")) {
                int first = lines[i].toString().indexOf("!|");
                int last = lines[i].toString().length();
                String Heading = lines[i].toString().substring(first + 2, last - 1);
                FitnesseTablesList.addItem(Heading);
            } else if (lines[i].toString().contains("|Script") || lines[i].toString().contains("|Subset Query")
                    || lines[i].toString().contains("|Query") || lines[i].toString().startsWith("|Start", 0)) {
                try {
                    int last = lines[i].toString().length();
                    int splitElements = lines[i].toString().indexOf("|", 1);
                    String Heading = lines[i].toString().substring(splitElements + 1, last - 1);
                    FitnesseTablesList.addItem(Heading);
                } catch (Exception E) {

                }

            }
            if (lines[i].toString().contains("|Subset Query") || lines[i].toString().contains("|Query")) {
                try {
                    int last = lines[i].toString().length();
                    int splitElements = lines[i].toString().indexOf(":", 1);
                    String Heading = lines[i].toString().substring(splitElements + 1, last - 1);
                    FitnesseTablesList.addItem(Heading);
                } catch (Exception E) {

                }
            }
        }
    }//GEN-LAST:event_jTree1MouseClicked

    private void btn_SaveFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SaveFileActionPerformed

        try {
            BufferedWriter bWriter = new BufferedWriter(new FileWriter(JtreePath));
            bWriter.write(PreviewTextArea.getText());
            bWriter.close();

        } catch (IOException ex) {
            Logger.getLogger(FitnesseRefactor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_btn_SaveFileActionPerformed

    private void toTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toTxtActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_toTxtActionPerformed

    private void AddTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddTableActionPerformed
        ProgressBar.setValue(0);
        ProgressBar.setMinimum(0);
        if (ParentFolder.isSelected()) {
            if (!"".equals(JtreePath)) {
                File dir = new File(JtreePath);
                try {
                    if (dir.getParent() != null && dir.isFile()) {
                        String Testcase = dir.getParent();
                        File dir1 = new File(Testcase);
                        if (dir1.getParent() != null && dir1.isDirectory()) {
                            String parent = dir1.getParent();
                            File dir2 = new File(Testcase);
                            if (dir2.getParent() != null) {
                                String GrandParent = dir2.getParent();
                                File dir3 = new File(GrandParent);
                                File[] allFiles = dir3.listFiles();
                                ArrayList al = new ArrayList();
                                for (File file : allFiles) {
                                    String TestcaseNames = file.getName();
                                    al.add(TestcaseNames);
                                }
                                if (!fromTxt.getText().isEmpty() && !toTxt.getText().isEmpty()) {
                                    int FromTxtInt = Integer.parseInt(fromTxt.getText());
                                    int ToTxtInt = Integer.parseInt(toTxt.getText());
                                    int TotFiles = al.size();
                                    if ((ToTxtInt > FromTxtInt) && (ToTxtInt > 0) && (FromTxtInt > 0)
                                            && ToTxtInt <= al.size() - 2) {
                                        for (int removeAfterToIndx = (ToTxtInt
                                                + 2); removeAfterToIndx < TotFiles; removeAfterToIndx++) {
                                            al.remove(ToTxtInt + 2);
                                        }
                                        if (FromTxtInt > 1) {
                                            for (int removeFromIndx = 1; removeFromIndx < FromTxtInt; removeFromIndx++) {
                                                al.remove(2);
                                            }
                                        }

                                    } else {
                                        JOptionPane.showMessageDialog(null,
                                                "FROM test case number cannot be greater/equal to TO test case number.\nFROM and TO test case numbers should be greater than zero. \nTO test case number should not be greater than the testcase count ",
                                                "Warning", JOptionPane.WARNING_MESSAGE);
                                    }
                                }
                                ProgressBar.setMaximum(al.size() - 2);
                                //ProgressBar.setValue(5);
                                int progressCount = 0;
                                for (int i = 2; i <= al.size(); i++) {
                                    System.out.println(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    File EachFile = new File(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    for (int j = 0; j < FileUtils.readLines(EachFile).size(); j++) {
                                        String line = (String) FileUtils.readLines(EachFile).get(j);

                                        if (line.matches("(.*)" + FitnesseTablesList.getSelectedItem().toString()
                                                + "(.*)")) {
                                            p = j;
                                            ReadAllLines(EachFile);
                                            int linNum = CountLines(EachFile);
                                            int selectTableSize = SizeOfTable(EachFile);
                                            AddTable();
                                            int AddedLinesLen = AddedLines.size();
                                            int tblIndex = 1;
                                            for (int SetNewLines = 0; SetNewLines < AddedLinesLen; SetNewLines++) {
                                                AllLines.add(p + selectTableSize + tblIndex,
                                                        AddedLines.get(SetNewLines).toString());
                                                tblIndex = tblIndex + 1;
                                            }
                                            AllLines.add(p + selectTableSize + tblIndex, "");
                                            WriteAllLines(EachFile);
                                            break;

                                        } else if (line.matches("(.*)" + FitnesseTablesList.getItemAt(1) + "(.*)")
                                                && FitnesseTablesList.getSelectedItem().toString()
                                                        .contains("Select an item")) {
                                            p = j;
                                            int r = p;
                                            ReadAllLines(EachFile);
                                            AddTable();
                                            int AddedLinesLen = AddedLines.size();
                                            for (int SetNewLines = 0; SetNewLines < AddedLinesLen; SetNewLines++) {
                                                AllLines.add(r, AddedLines.get(SetNewLines).toString());
                                                r = r + 1;
                                            }
                                            AllLines.add(r, "");
                                            WriteAllLines(EachFile);
                                            break;
                                        }
                                    }
                                    progressCount = progressCount + 1;
                                    ProgressBar.setValue(progressCount);
                                }

                            } else {
                                JOptionPane.showMessageDialog(null,
                                        "There are no testcases under the parent folder", "Error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "There are no testcases under the parent folder",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Need to select atleast one content.txt file",
                                "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                } catch (Exception E) {
                    //JOptionPane.showMessageDialog(null, E, "Java Runtime Error", JOptionPane.ERROR );
                }
            }

        }

    }//GEN-LAST:event_AddTableActionPerformed

    private void FitnesseTablesListActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FitnesseTablesListActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_FitnesseTablesListActionPerformed

    private void DelTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DelTableActionPerformed
        if (ParentFolder.isSelected()) {
            if (!"".equals(JtreePath)) {
                File dir = new File(JtreePath);
                try {
                    if (dir.getParent() != null && dir.isFile()) {
                        String Testcase = dir.getParent();
                        File dir1 = new File(Testcase);
                        if (dir1.getParent() != null && dir1.isDirectory()) {
                            String parent = dir1.getParent();
                            File dir2 = new File(Testcase);
                            if (dir2.getParent() != null) {
                                String GrandParent = dir2.getParent();
                                File dir3 = new File(GrandParent);
                                File[] allFiles = dir3.listFiles();
                                ArrayList al = new ArrayList();
                                for (File file : allFiles) {
                                    String TestcaseNames = file.getName();
                                    al.add(TestcaseNames);
                                }
                                if (!fromTxt.getText().isEmpty() && !toTxt.getText().isEmpty()) {
                                    int FromTxtInt = Integer.parseInt(fromTxt.getText());
                                    int ToTxtInt = Integer.parseInt(toTxt.getText());
                                    int TotFiles = al.size();
                                    if ((ToTxtInt > FromTxtInt) && (ToTxtInt > 0) && (FromTxtInt > 0)
                                            && ToTxtInt <= al.size() - 2) {
                                        for (int removeAfterToIndx = (ToTxtInt
                                                + 2); removeAfterToIndx < TotFiles; removeAfterToIndx++) {
                                            al.remove(ToTxtInt + 2);
                                        }
                                        if (FromTxtInt > 1) {
                                            for (int removeFromIndx = 1; removeFromIndx < FromTxtInt; removeFromIndx++) {
                                                al.remove(2);
                                            }
                                        }

                                    } else {
                                        JOptionPane.showMessageDialog(null,
                                                "FROM test case number cannot be greater/equal to TO test case number.\nFROM and TO test case numbers should be greater than zero. \nTO test case number should not be greater than the testcase count ",
                                                "Warning", JOptionPane.WARNING_MESSAGE);
                                    }
                                }
                                for (int i = 2; i <= al.size(); i++) {
                                    System.out.println(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    File EachFile = new File(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    for (int j = 0; j < FileUtils.readLines(EachFile).size(); j++) {
                                        String line = (String) FileUtils.readLines(EachFile).get(j);
                                        if (line.matches("(.*)" + FitnesseTablesList.getSelectedItem().toString()
                                                + "(.*)")) {
                                            p = j;
                                            ReadAllLines(EachFile);
                                            int selectTableSize = SizeOfTable(EachFile);
                                            for (int DeleteLines = 0; DeleteLines <= selectTableSize; DeleteLines++) {
                                                AllLines.remove(p);
                                            }
                                            WriteAllLines(EachFile);
                                        }
                                    }
                                }
                            } else {
                                JOptionPane.showMessageDialog(null,
                                        "There are no testcases under the parent folder", "Error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "There are no testcases under the parent folder",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Need to select atleast one content.txt file",
                                "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                } catch (Exception E) {
                    //JOptionPane.showMessageDialog(null, E, "Java Runtime Error", JOptionPane.ERROR );
                }
            }

        }
    }//GEN-LAST:event_DelTableActionPerformed

    private void PreviewTextAreaMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_PreviewTextAreaMouseClicked
        int CursorLocation = PreviewTextArea.getCaretPosition();
        try {
            int RowPosition = PreviewTextArea.getLineOfOffset(CursorLocation) + 1;
            RowNoDisplay.setText(String.valueOf(RowPosition));
            int ColumnPosition = PreviewTextArea.getLineStartOffset(RowPosition - 1);
            int ClNo = CursorLocation - ColumnPosition;
            ColumnNoDisplay.setText(String.valueOf(ClNo));

        } catch (BadLocationException ex) {
            Logger.getLogger(FitnesseRefactor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_PreviewTextAreaMouseClicked

    private void fromTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_fromTxtActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_fromTxtActionPerformed

    private void ColumnFieldActionPerformed(java.awt.event.ActionEvent evt) {

    }

    private void AddColumnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddColumnActionPerformed

        if (ParentFolder.isSelected()) {
            if (!"".equals(JtreePath)) {
                File dir = new File(JtreePath);
                try {
                    if (dir.getParent() != null && dir.isFile()) {
                        String Testcase = dir.getParent();
                        File dir1 = new File(Testcase);
                        if (dir1.getParent() != null && dir1.isDirectory()) {
                            String parent = dir1.getParent();
                            File dir2 = new File(Testcase);
                            if (dir2.getParent() != null) {
                                String GrandParent = dir2.getParent();
                                File dir3 = new File(GrandParent);
                                File[] allFiles = dir3.listFiles();
                                ArrayList al = new ArrayList();
                                for (File file : allFiles) {
                                    if (allFiles.length <= al.size())
                                        break;
                                    String TestcaseNames = file.getName();
                                    al.add(TestcaseNames);
                                }
                                if (!fromTxt.getText().isEmpty() && !toTxt.getText().isEmpty()) {
                                    int FromTxtInt = Integer.parseInt(fromTxt.getText());
                                    int ToTxtInt = Integer.parseInt(toTxt.getText());
                                    int TotFiles = al.size();
                                    if ((ToTxtInt > FromTxtInt) && (ToTxtInt > 0) && (FromTxtInt > 0)
                                            && ToTxtInt <= al.size() - 2) {
                                        for (int removeAfterToIndx = (ToTxtInt
                                                + 2); removeAfterToIndx < TotFiles; removeAfterToIndx++) {
                                            al.remove(ToTxtInt + 2);
                                        }
                                        if (FromTxtInt > 1) {
                                            for (int removeFromIndx = 1; removeFromIndx < FromTxtInt; removeFromIndx++) {
                                                al.remove(2);
                                            }
                                        }

                                    } else {
                                        JOptionPane.showMessageDialog(null,
                                                "FROM test case number cannot be greater/equal to TO test case number.\nFROM and TO test case numbers should be greater than zero. \nTO test case number should not be greater than the testcase count ",
                                                "Warning", JOptionPane.WARNING_MESSAGE);
                                    }
                                }
                                for (int i = 2; i <= al.size(); i++) {
                                    System.out.println(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    File EachFile = new File(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    for (int j = 0; j < FileUtils.readLines(EachFile).size(); j++) {
                                        String line = (String) FileUtils.readLines(EachFile).get(j);
                                        if (line.matches("(.*)" + FitnesseTablesList.getSelectedItem().toString()
                                                + "(.*)")) {
                                            p = j;
                                            ReadAllLines(EachFile);
                                            int linNum = CountLines(EachFile);
                                            ModifiedTable(EachFile, Integer.parseInt(ColumnField.getText()));
                                            int ModifiedLen = ModifiedLines.size();
                                            System.out.println(ModifiedLen);
                                            int tblIndex = 1;
                                            for (int SetNew = 0; SetNew < ModifiedLen; SetNew++) {
                                                AllLines.set(p + tblIndex, ModifiedLines.get(SetNew).toString());
                                                tblIndex = tblIndex + 1;
                                            }
                                            WriteAllLines(EachFile);
                                        }
                                    }
                                }
                            } else {
                                JOptionPane.showMessageDialog(null,
                                        "There are no testcases under the parent folder", "Error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "There are no testcases under the parent folder",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Need to select atleast one content.txt file",
                                "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                } catch (Exception E) {
                    //JOptionPane.showMessageDialog(null, E, "Java Runtime Error", JOptionPane.ERROR );
                }
            }

        }
    }//GEN-LAST:event_AddColumnActionPerformed

    private void PreviewTextAreaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_PreviewTextAreaKeyPressed
        int CursorLocation = PreviewTextArea.getCaretPosition();
        try {
            int RowPosition = PreviewTextArea.getLineOfOffset(CursorLocation) + 1;
            RowNoDisplay.setText(String.valueOf(RowPosition));
            int ColumnPosition = PreviewTextArea.getLineStartOffset(RowPosition - 1);
            int ClNo = CursorLocation - ColumnPosition;
            ColumnNoDisplay.setText(String.valueOf(ClNo));

        } catch (BadLocationException ex) {
            Logger.getLogger(FitnesseRefactor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_PreviewTextAreaKeyPressed

    private void deleteColBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteColBtnActionPerformed
        if (ParentFolder.isSelected()) {
            if (!"".equals(JtreePath)) {
                File dir = new File(JtreePath);
                try {
                    if (dir.getParent() != null && dir.isFile()) {
                        String Testcase = dir.getParent();
                        File dir1 = new File(Testcase);
                        if (dir1.getParent() != null && dir1.isDirectory()) {
                            String parent = dir1.getParent();
                            File dir2 = new File(Testcase);
                            if (dir2.getParent() != null) {
                                String GrandParent = dir2.getParent();
                                File dir3 = new File(GrandParent);
                                File[] allFiles = dir3.listFiles();
                                ArrayList al = new ArrayList();
                                for (File file : allFiles) {
                                    String TestcaseNames = file.getName();
                                    al.add(TestcaseNames);
                                }
                                if (!fromTxt.getText().isEmpty() && !toTxt.getText().isEmpty()) {
                                    int FromTxtInt = Integer.parseInt(fromTxt.getText());
                                    int ToTxtInt = Integer.parseInt(toTxt.getText());
                                    int TotFiles = al.size();
                                    if ((ToTxtInt > FromTxtInt) && (ToTxtInt > 0) && (FromTxtInt > 0)
                                            && ToTxtInt <= al.size() - 2) {
                                        for (int removeAfterToIndx = (ToTxtInt
                                                + 2); removeAfterToIndx < TotFiles; removeAfterToIndx++) {
                                            al.remove(ToTxtInt + 2);
                                        }
                                        if (FromTxtInt > 1) {
                                            for (int removeFromIndx = 1; removeFromIndx < FromTxtInt; removeFromIndx++) {
                                                al.remove(2);
                                            }
                                        }

                                    } else {
                                        JOptionPane.showMessageDialog(null,
                                                "FROM test case number cannot be greater/equal to TO test case number.\nFROM and TO test case numbers should be greater than zero. \nTO test case number should not be greater than the testcase count ",
                                                "Warning", JOptionPane.WARNING_MESSAGE);
                                    }
                                }
                                for (int i = 2; i <= al.size(); i++) {
                                    System.out.println(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    File EachFile = new File(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    for (int j = 0; j < FileUtils.readLines(EachFile).size(); j++) {
                                        String line = (String) FileUtils.readLines(EachFile).get(j);
                                        if (line.matches("(.*)" + FitnesseTablesList.getSelectedItem().toString()
                                                + "(.*)")) {
                                            p = j;
                                            ReadAllLines(EachFile);
                                            int linNum = CountLines(EachFile);
                                            DeleteColumn(EachFile, Integer.parseInt(ColumnField.getText()));
                                            int DelColsLen = DeletedSubLines.size();
                                            int tblIndex = 1;
                                            for (int SetNew = 0; SetNew < DelColsLen; SetNew++) {
                                                AllLines.set(p + tblIndex, DeletedSubLines.get(SetNew).toString());
                                                tblIndex = tblIndex + 1;
                                            }
                                            WriteAllLines(EachFile);
                                        }
                                    }
                                }
                            } else {
                                JOptionPane.showMessageDialog(null,
                                        "There are no testcases under the parent folder", "Error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "There are no testcases under the parent folder",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Need to select atleast one content.txt file",
                                "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                } catch (Exception E) {
                    //JOptionPane.showMessageDialog(null, E, "Java Runtime Error", JOptionPane.ERROR );
                }
            }

        }
    }//GEN-LAST:event_deleteColBtnActionPerformed

    private void RowFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RowFieldActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_RowFieldActionPerformed

    private void ReplaceAllBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReplaceAllBtnActionPerformed
        if (ParentFolder1.isSelected()) {
            if (!"".equals(JtreePath)) {
                File dir = new File(JtreePath);
                try {
                    if (dir.getParent() != null && dir.isFile()) {
                        String Testcase = dir.getParent();
                        File dir1 = new File(Testcase);
                        if (dir1.getParent() != null && dir1.isDirectory()) {
                            String parent = dir1.getParent();
                            File dir2 = new File(Testcase);
                            if (dir2.getParent() != null) {
                                String GrandParent = dir2.getParent();
                                File dir3 = new File(GrandParent);
                                File[] allFiles = dir3.listFiles();
                                ArrayList al = new ArrayList();
                                for (File file : allFiles) {
                                    String TestcaseNames = file.getName();
                                    al.add(TestcaseNames);
                                }
                                if (!fromTxt.getText().isEmpty() && !toTxt.getText().isEmpty()) {
                                    int FromTxtInt = Integer.parseInt(fromTxt.getText());
                                    int ToTxtInt = Integer.parseInt(toTxt.getText());
                                    int TotFiles = al.size();
                                    if ((ToTxtInt > FromTxtInt) && (ToTxtInt > 0) && (FromTxtInt > 0)
                                            && ToTxtInt <= al.size() - 2) {
                                        for (int removeAfterToIndx = (ToTxtInt
                                                + 2); removeAfterToIndx < TotFiles; removeAfterToIndx++) {
                                            al.remove(ToTxtInt + 2);
                                        }
                                        if (FromTxtInt > 1) {
                                            for (int removeFromIndx = 1; removeFromIndx < FromTxtInt; removeFromIndx++) {
                                                al.remove(2);
                                            }
                                        }

                                    } else {
                                        JOptionPane.showMessageDialog(null,
                                                "FROM test case number cannot be greater/equal to TO test case number.\nFROM and TO test case numbers should be greater than zero. \nTO test case number should not be greater than the testcase count ",
                                                "Warning", JOptionPane.WARNING_MESSAGE);
                                    }
                                }
                                for (int i = 2; i <= al.size(); i++) {
                                    System.out.println(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    File EachFile = new File(dir2.getParent() + "\\" + al.get(i) + "\\content.txt");
                                    for (int j = 0; j < FileUtils.readLines(EachFile).size(); j++) {
                                        String line = (String) FileUtils.readLines(EachFile).get(j);
                                        if (line.matches("(.*)" + FitnesseTablesList.getSelectedItem().toString()
                                                + "(.*)")) {
                                            p = j;
                                            ReplacedLines = new ArrayList();
                                            ReadAllLines(EachFile);
                                            getTable(EachFile);
                                            int SelectedTable = getTable(EachFile).size();
                                            for (int RepLines = 0; RepLines < SelectedTable; RepLines++) {
                                                ReplaceValue(EachFile, getTable(EachFile).get(RepLines).toString());
                                            }
                                            int c = 0;
                                            for (int Replace = p; Replace < SelectedTable + p; Replace++) {
                                                AllLines.set(Replace, ReplacedLines.get(c));
                                                c++;
                                            }
                                            WriteAllLines(EachFile);
                                        }
                                    }
                                }
                            } else {
                                JOptionPane.showMessageDialog(null,
                                        "There are no testcases under the parent folder", "Error",
                                        JOptionPane.ERROR_MESSAGE);
                            }
                        } else {
                            JOptionPane.showMessageDialog(null, "There are no testcases under the parent folder",
                                    "Error", JOptionPane.ERROR_MESSAGE);
                        }
                    } else {
                        JOptionPane.showMessageDialog(null, "Need to select atleast one content.txt file",
                                "Warning", JOptionPane.WARNING_MESSAGE);
                    }
                } catch (Exception E) {
                    //JOptionPane.showMessageDialog(null, E, "Java Runtime Error", JOptionPane.ERROR );
                }
            }

        }

    }//GEN-LAST:event_ReplaceAllBtnActionPerformed

    private void ParentFolder1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ParentFolder1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_ParentFolder1ActionPerformed

    private void FindWhatTxtActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_FindWhatTxtActionPerformed

    }//GEN-LAST:event_FindWhatTxtActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FitnesseRefactor.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FitnesseRefactor.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FitnesseRefactor.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FitnesseRefactor.class.getName()).log(java.util.logging.Level.SEVERE,
                    null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new FitnesseRefactor().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddColumn;
    private javax.swing.JButton AddTable;
    private javax.swing.JTextField ColumnField;
    private javax.swing.JLabel ColumnNo;
    private javax.swing.JLabel ColumnNoDisplay;
    private javax.swing.JButton DelTable;
    private javax.swing.JTextArea EditArea;
    private javax.swing.JTextField EndIndexTxt;
    private javax.swing.JTextField FindWhatTxt;
    private javax.swing.JComboBox FitnesseTablesList;
    private javax.swing.JLabel FromLbl;
    private javax.swing.JScrollPane JtreeScroll;
    private javax.swing.JLabel LblPreview;
    private javax.swing.JLabel Lbl_table;
    private javax.swing.JCheckBox ParentFolder;
    private javax.swing.JCheckBox ParentFolder1;
    private javax.swing.JScrollPane PreviewScroll;
    private javax.swing.JTextArea PreviewTextArea;
    private javax.swing.JProgressBar ProgressBar;
    private javax.swing.JButton ReplaceAllBtn;
    private javax.swing.JTextField ReplaceWithTxt;
    private javax.swing.JTextField RowField;
    private javax.swing.JLabel RowLbl;
    private javax.swing.JLabel RowNoDisplay;
    private javax.swing.JTextField StartIndexTxt;
    private javax.swing.JPanel TablesList;
    private javax.swing.JLabel ToLbl;
    private javax.swing.JButton btn_SaveFile;
    private javax.swing.JButton deleteColBtn;
    private javax.swing.JTextField fromTxt;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenu jMenu4;
    private javax.swing.JMenuBar jMenuBar2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField5;
    private javax.swing.JTextField jTextField6;
    private javax.swing.JTree jTree1;
    private javax.swing.JTextField toTxt;
    // End of variables declaration//GEN-END:variables
    private String JtreePath;
    public ArrayList ModifiedLines;
    public ArrayList AllLines;
    public ArrayList DeletedSubLines;
    public ArrayList AddedLines;
    public ArrayList ReplacedLines;

    private void setIcon() {
        setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("fitnesseRefactor.ico")));
    }

    public void ReplaceValue(File file, String RowString) throws IOException {

        if (StartIndexTxt.getText() != null && EndIndexTxt.getText() != null) {
            String s = RowString;
            StringBuffer buff = new StringBuffer(s);

            String RowSubString = s.substring(Integer.parseInt(StartIndexTxt.getText()),
                    Integer.parseInt(EndIndexTxt.getText()));
            String RowSubString1 = RowSubString.replace(FindWhatTxt.getText().toString(),
                    ReplaceWithTxt.getText().toString());
            String NewRowString = buff.replace(Integer.parseInt(StartIndexTxt.getText()),
                    Integer.parseInt(EndIndexTxt.getText()), RowSubString1).toString();
            ReplacedLines.add(NewRowString);
        } else {
            String s = RowString;
            String RowSubString = s.replaceAll(FindWhatTxt.getText(), ReplaceWithTxt.getText());
            ReplacedLines.add(RowSubString);
        }
    }

    public void DeleteColumn(File file, int ColumnNum) throws IOException {
        String DeletedSubString;
        DeletedSubLines = new ArrayList();
        ArrayList noOfPipes = new ArrayList();
        int k = 1;
        int t = 0;
        do {
            DeletedSubString = (String) FileUtils.readLines(file).get(p + k);
            if (DeletedSubString.isEmpty()) {
                break;
            }
            StringBuffer buff = new StringBuffer(DeletedSubString);
            for (int pipes = 0; pipes < DeletedSubString.length(); pipes++) {
                char ch = DeletedSubString.charAt(pipes);
                if (ch == '|') {
                    noOfPipes.add(pipes);
                }
            }
            int TotalPipes = noOfPipes.size();
            buff.replace((int) noOfPipes.get(ColumnNum - 1), (int) noOfPipes.get(ColumnNum), "");
            DeletedSubLines.add(buff.toString());
            k++;
            t++;
        } while (!DeletedSubLines.isEmpty());
    }

    public int SizeOfTable(File file) throws IOException {
        int l = p + 1;
        String lineInTable;
        int TotalLinesInTable = 0;
        do {
            lineInTable = (String) FileUtils.readLines(file).get(l);
            TotalLinesInTable = TotalLinesInTable + 1;
            l++;
        } while (!lineInTable.isEmpty());
        return TotalLinesInTable;
    }

    public List getTable(File file) throws IOException {
        int l = p;
        String lineInTable;
        List TableLines = new ArrayList();
        do {
            lineInTable = (String) FileUtils.readLines(file).get(l);
            if (lineInTable.isEmpty()) {
                break;
            }
            TableLines.add(lineInTable);
            l++;
        } while (!lineInTable.isEmpty());
        return TableLines;
    }

    public void ModifiedTable(File file, int ColumnNum) throws IOException {
        int TotalColData = EditArea.getLineCount();
        if (TotalColData != 0) {
            String[] ColumnData = EditArea.getText().split("\\n");
            String ModifiedLine;
            ModifiedLines = new ArrayList();
            ArrayList noOfPipes = new ArrayList();
            int l = p + 1;
            String line;
            int TotalLinesInTable = 0;
            do {
                line = (String) FileUtils.readLines(file).get(l);
                TotalLinesInTable = TotalLinesInTable + 1;
                l++;
            } while (!line.isEmpty());
            int k = 1;
            int t = 0;
            do {
                ModifiedLine = (String) FileUtils.readLines(file).get(p + k);
                if (ModifiedLine.isEmpty()) {
                    break;
                }
                StringBuffer buff = new StringBuffer(ModifiedLine);
                for (int pipes = 0; pipes < ModifiedLine.length(); pipes++) {
                    char ch = ModifiedLine.charAt(pipes);
                    if (ch == '|') {
                        noOfPipes.add(pipes);
                    }
                }
                int TotalPipes = noOfPipes.size();
                int length = ColumnData.length;
                if (length > t && !ColumnData[t].isEmpty()) {
                    buff.insert((int) noOfPipes.get(ColumnNum - 1), "|" + ColumnData[t]);
                    ModifiedLines.add(buff.toString());
                } else {
                    buff.insert((int) noOfPipes.get(ColumnNum - 1), "| ");
                    ModifiedLines.add(buff.toString());
                }
                k++;
                t++;
            } while (!ModifiedLine.isEmpty());
        } else {
            JOptionPane.showMessageDialog(null, "Please enter the column header to added the column", "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
    }

    public void AddTable() {
        String[] ColumnData = EditArea.getText().split("\\n");
        AddedLines = new ArrayList();
        int length = ColumnData.length;
        for (int lines = 0; lines < length; lines++) {
            AddedLines.add(ColumnData[lines]);
        }

    }

    public int CountLines(File filename) throws FileNotFoundException, IOException {
        LineNumberReader reader = new LineNumberReader(new FileReader(filename));
        int cnt = 0;
        String lineRead = "";
        while ((lineRead = reader.readLine()) != null) {
        }
        cnt = reader.getLineNumber();
        reader.close();
        return cnt;
    }

    public void ReadAllLines(File tfile) throws IOException {
        AllLines = new ArrayList<String>();
        int linNum = CountLines(tfile);
        for (int LineColl = 0; LineColl < linNum; LineColl++) {
            String lines = (String) FileUtils.readLines(tfile).get(LineColl);
            AllLines.add(lines);
        }
    }

    public void WriteAllLines(File wfile) throws IOException {
        FileUtils.writeLines(wfile, AllLines);
    }
}