コード例 #1
0
ファイル: ModelUtil.java プロジェクト: janarne/AT
  public static void bindModelToView(ArrayList fieldsToBind, DomainObject model) {

    BeanAdapter adapter = new BeanAdapter(model, true);
    ValueModel valueModel = null;
    Object field = null;
    ATFieldInfo fieldInfo;
    String fieldName = "";
    ComboBoxAdapter comboBoxAdapter = null;

    for (int i = 0; i < fieldsToBind.size(); i++) {
      field = fieldsToBind.get(i);
      fieldName = ((JComponent) field).getName();
      valueModel = adapter.getValueModel(fieldName);
      if (!ignoreArray.contains(fieldName)) {
        if (field instanceof JFormattedTextField) {
          Bindings.bind((JFormattedTextField) field, valueModel);
        } else if (field instanceof JTextComponent) {
          //						Bindings.bind((JTextComponent) field, valueModel);
        } else if (field instanceof JCheckBox) {
          Bindings.bind((JCheckBox) field, valueModel);
        } else if (field instanceof JComboBox) {
          fieldInfo = ATFieldInfo.getFieldInfo(model.getClass().getName() + "." + fieldName);
          if (fieldInfo != null) {
            Vector<String> values = LookupListUtils.getLookupListValues(fieldInfo.getLookupList());
            if (values != null) {
              comboBoxAdapter = new ComboBoxAdapter(values, valueModel);
              ((JComboBox) field).setModel(comboBoxAdapter);
            }
          }
        } else {
          System.out.println(fieldName + " not bound");
        }
      }
    }
  }
 public void removeRelatedTableRow(DomainGlazedListTable relatedTable, DomainObject model)
     throws ObjectNotRemovedException {
   int selectedRow = relatedTable.getSelectedRow();
   if (selectedRow == -1) {
     JOptionPane.showMessageDialog(
         this, "You must select a row to remove.", "warning", JOptionPane.WARNING_MESSAGE);
   } else {
     int response =
         JOptionPane.showConfirmDialog(
             this,
             "Are you sure you want to delete "
                 + relatedTable.getSelectedRows().length
                 + " record(s)",
             "Delete records",
             JOptionPane.YES_NO_OPTION);
     if (response == JOptionPane.OK_OPTION) {
       ArrayList<DomainObject> relatedObjects = relatedTable.removeSelectedRows();
       for (DomainObject relatedObject : relatedObjects) {
         model.removeRelatedObject(relatedObject);
       }
       int rowCount = relatedTable.getRowCount();
       if (rowCount == 0) {
         // do nothing
       } else if (selectedRow >= rowCount) {
         relatedTable.setRowSelectionInterval(rowCount - 1, rowCount - 1);
       } else {
         relatedTable.setRowSelectionInterval(selectedRow, selectedRow);
       }
       // set record to dirty
       ApplicationFrame.getInstance().setRecordDirty();
     }
   }
 }