Пример #1
0
 /**
  * Fills JTable with selected group
  *
  * @param words data to be displayed in table
  * @param newSet true if creating new set, false otherwise
  */
 public void setGroup(final Vector<Word> words, boolean newSet) {
   Object[] columns = {"Word", "Translation"};
   if (newSet) {
     tableModel = new DefaultTableModel(5, 2);
     tableModel.setColumnIdentifiers(columns);
   } else {
     Object[][] rows = new Object[words.size()][2];
     int i = 0;
     for (Word word : words) {
       rows[i][0] = word.getToTranslate();
       rows[i][1] = word.getTranslation();
       i++;
     }
     tableModel = new DefaultTableModel(rows, columns);
   }
   // table = new JTable(tableModel);
   table.setModel(tableModel);
   tableModel.addTableModelListener(
       new TableModelListener() {
         public void tableChanged(TableModelEvent arg0) {
           getRootPane().setDefaultButton(saveButton);
           saveButton.setEnabled(true);
         }
       });
 }
Пример #2
0
 @Override
 public void updateWord(Word word) {
   Db_Help dbhelper = new Db_Help(mContext);
   String query =
       "UPDATE tb_words SET vocab='"
           + word.getVocab()
           + "'"
           + ",meaning='"
           + word.getMeaning()
           + "',pronunciation='"
           + word.getPronunciation()
           + "' WHERE _id='"
           + word.getId()
           + "'";
   Log.e("DB_QUERY", query);
   dbhelper.executeQuery(query);
 }
Пример #3
0
  @Override
  public void insertWord(Word word) {
    Db_Help dbhelper = new Db_Help(mContext);
    Common_helper common_helper = new Common_helper(mContext);

    String query =
        "INSERT INTO tb_words VALUES ('"
            + common_helper.getGUID()
            + "',"
            + "'"
            + word.getVocab()
            + "',"
            + "'"
            + word.getPronunciation()
            + "',"
            + "'"
            + word.getMeaning()
            + "');";
    Log.e("DB_QUERY", query);
    dbhelper.executeQuery(query);
  }
Пример #4
0
  @Override
  public Word getWord(Word word) {
    Db_Help dbhelper = new Db_Help(mContext);
    String query =
        "SELECT _id,vocab,pronunciation,meaning FROM tb_words WHERE _id='" + word.getId() + "'";
    Word result = new Word();
    ArrayList datarow = new ArrayList();
    datarow = dbhelper.getDataRow(query);

    if (datarow.size() != 0) {
      HashMap tablerow = new HashMap();
      tablerow = (HashMap) datarow.get(0);
      result =
          new Word(
              tablerow.get(tbWord.id).toString(),
              tablerow.get(tbWord.vocab).toString(),
              tablerow.get(tbWord.prounuciation).toString(),
              tablerow.get(tbWord.meaning).toString());
    }

    return result;
  }
Пример #5
0
 @Override
 public void deleteWord(Word word) {
   Db_Help dbhelper = new Db_Help(mContext);
   String query = "DELETE FROM tb_words where _id='" + word.getId() + "'";
   dbhelper.executeQuery(query);
 }