private void newEntry() {
   DataEntryDialog dialog = new DataEntryDialog(shell);
   dialog.setLabels(columnNames);
   String[] data = dialog.open();
   if (data != null) {
     TableItem item = new TableItem(table, SWT.NONE);
     item.setText(data);
     isModified = true;
   }
 }
 private void editEntry(TableItem item) {
   DataEntryDialog dialog = new DataEntryDialog(shell);
   dialog.setLabels(columnNames);
   String[] values = new String[table.getColumnCount()];
   for (int i = 0; i < values.length; i++) {
     values[i] = item.getText(i);
   }
   dialog.setValues(values);
   values = dialog.open();
   if (values != null) {
     item.setText(values);
     isModified = true;
   }
 }
  private boolean findMatch(
      String searchString, TableItem item, int column, boolean matchWord, boolean matchCase) {

    String tableText = matchCase ? item.getText(column) : item.getText(column).toLowerCase();
    if (matchWord) {
      if (tableText != null && tableText.equals(searchString)) {
        return true;
      }

    } else {
      if (tableText != null && tableText.indexOf(searchString) != -1) {
        return true;
      }
    }
    return false;
  }
 private void launchEditor(TableItem item) {
   String theCommand = resUser.getString("Custom_editor");
   theCommand = theCommand.replaceAll("%file%", item.getText(3));
   theCommand = theCommand.replaceAll("%line%", item.getText(1));
   theCommand = theCommand.replace('/', File.separatorChar);
   theCommand = theCommand.replaceAll("%slash%", "/");
   try {
     Runtime.getRuntime().exec(theCommand);
   } catch (IOException e) {
     displayError("Error launching editor: " + e.getMessage());
   }
 }
  private void openAddressBook() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"});
    fileDialog.setFilterNames(
        new String[] {
          resAddressBook.getString("Book_filter_name") + " (*.adr)",
          resAddressBook.getString("All_filter_name") + " (*.*)"
        });
    String name = fileDialog.open();

    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resAddressBook.getString("File")
              + file.getName()
              + " "
              + resAddressBook.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    int writeIndex = 0;
    for (int i = 0; i < data.length; i++) {
      String[] line = decodeLine(data[i]);
      if (line != null) tableInfo[writeIndex++] = line;
    }
    if (writeIndex != data.length) {
      String[][] result = new String[writeIndex][table.getColumnCount()];
      System.arraycopy(tableInfo, 0, result, 0, writeIndex);
      tableInfo = result;
    }
    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName());
    isModified = false;
    this.file = file;
  }
  private void openAddressBook(String name) {
    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resMessages.getString("File")
              + file.getName()
              + " "
              + resMessages.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);
      waitCursor.dispose();

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    for (int i = 0; i < data.length; i++) {
      tableInfo[i] = decodeLine(data[i]);
    }

    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    this.file = file;
  }
  private void openFile(String fileName, Table table) {
    String outStr;
    try {

      CSVReader reader = new CSVReader(new FileReader(fileName), ',', '"');
      String[] strLineArr;

      // Open the file that is the first
      // command line parameter
      FileInputStream fstream = new FileInputStream(fileName);
      // Get the object of DataInputStream
      DataInputStream in = new DataInputStream(fstream);
      BufferedReader br = new BufferedReader(new InputStreamReader(in));
      String strLine;

      table.clearAll();
      table.removeAll();
      table.redraw();

      int length = 0;
      boolean first = true;
      // Read File Line By Line
      while ((strLineArr = reader.readNext()) != null) {
        // while ((strLine = br.readLine()) != null)   {
        // Print the content on the console
        // outStr = strLine;
        TableItem item = null;

        if (first) {
          length = strLineArr.length;
        } else {
          item = new TableItem(table, SWT.NONE);
        }

        int thisLen = strLineArr.length;
        if (thisLen <= length) {
          // String[] line = new String[length];
          for (int i = 0; i < thisLen; i++) {
            // line[i] = st.nextToken();
            // item.setText (i, st.nextToken());
            if (first) {
              TableColumn column = new TableColumn(table, SWT.NONE);
              column.setText(strLineArr[i]);
            } else {

              // System.out.println("-- "+i+" -- " + strLineArr[i]);
              item.setText(i, strLineArr[i]);
            }
          }
        }
        first = false;
      }

      // System.out.println("Finisehd file");

      for (int i = 0; i < length; i++) {
        table.getColumn(i).pack();
      }
      // System.out.println("finished packing");
      // Close the input stream
      in.close();
    } catch (Exception e) { // Catch exception if any
      System.err.println("Error: " + e.getMessage());
      e.printStackTrace();
    }
  }