List of usage examples for javax.swing JCheckBox getSelectedObjects
@BeanProperty(bound = false)
public Object[] getSelectedObjects()
null
if the button is not selected. From source file:nz.govt.natlib.ndha.manualdeposit.metadata.MetaDataElementCellEditor.java
public Object getCellEditorValue() { if (component.equals(componentCheck)) { final JCheckBox check = (JCheckBox) component; if (check.getSelectedObjects() == null) { return "false"; } else {/*w w w.j a v a 2s . c o m*/ return "true"; } } else if (component.equals(componentCombo)) { return ((JComboBox) component).getSelectedItem(); } else if (component.equals(componentDatePicker)) { final JXDatePicker date = (JXDatePicker) component; final Format formatter = new SimpleDateFormat(DATE_FORMAT, Locale.ENGLISH); if (date.getDate() == null) { return ""; } else { return formatter.format(date.getDate()); } } else if (component.equals(componentWholeNumber)) { return ((WholeNumberField) component).getText(); } else if (component.equals(componentDecimal)) { return ((DecimalNumberField) component).getText(); } else { return ((JTextField) component).getText(); } }
From source file:nz.govt.natlib.ndha.manualdeposit.MetaDataTest.java
@Test public final void testMetaDataCellEditor() { loadConfigFile();/*www . ja v a 2 s . c o m*/ AppProperties appProperties = null; try { appProperties = new AppProperties(); appProperties.setLoggedOnUser("mngroot"); appProperties.setLoggedOnUserPassword("mngroot"); } catch (Exception ex) { fail(); } MetaDataTableModel model = null; try { UserGroupData userGroupData = appProperties.getUserData().getUser(appProperties.getLoggedOnUser()) .getUserGroupData(); model = MetaDataTableModel.create(userGroupData, MetaDataFields.ECMSSystem.CMS2); } catch (Exception ex) { fail(); } Font standardFont = new Font("Arial", 0, 12); MetaDataElementCellEditor editor = new MetaDataElementCellEditor(standardFont); JTable table = new JTable(); table.setModel(model); IMetaDataTypeExtended meta = model.getRow(0); meta.setDataType(EDataType.Boolean); String value = "true"; Component comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(comp instanceof JCheckBox); JCheckBox chk = (JCheckBox) comp; assertTrue(chk.getSelectedObjects() != null); value = "false"; comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(editor.getCellEditorValue().equals(value)); meta.setDataType(EDataType.Date); String dateFormat = "dd/MM/yyyy"; SimpleDateFormat f = new SimpleDateFormat(dateFormat); value = "09/04/2008"; comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(comp instanceof JXDatePicker); JXDatePicker dt = (JXDatePicker) comp; Date theDate = dt.getDate(); String theDateString = f.format(theDate); assertTrue(value.equals(theDateString)); assertTrue(editor.getCellEditorValue().equals(value)); meta.setDataType(EDataType.Integer); value = "15"; comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(comp instanceof WholeNumberField); WholeNumberField num = (WholeNumberField) comp; assertTrue(num.getValue() == 15); assertTrue(editor.getCellEditorValue().equals(value)); meta.setDataType(EDataType.MultiSelect); ArrayList<MetaDataListValues> values = new ArrayList<MetaDataListValues>(); MetaDataListValues value1 = new MetaDataListValues("Item 1", "Item 1", 0); values.add(value1); MetaDataListValues value2 = new MetaDataListValues("Item 2", "Item 2", 1); values.add(value2); MetaDataListValues value3 = new MetaDataListValues("Item 3", "Item 3", 2); values.add(value3); meta.setListItems(values); comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(comp instanceof JComboBox); JComboBox cmb = (JComboBox) comp; cmb.setSelectedIndex(3); MetaDataListValues valueTest = (MetaDataListValues) cmb.getSelectedItem(); assertTrue(valueTest.equals(value3)); assertTrue(editor.getCellEditorValue().equals(value3)); meta.setDataType(EDataType.RealNumber); value = "30.5"; comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(comp instanceof DecimalNumberField); DecimalNumberField num2 = (DecimalNumberField) comp; assertTrue(num2.getValue() == 30.5); assertTrue(editor.getCellEditorValue().equals("30.50000")); meta.setDataType(EDataType.Text); value = "Hello World"; comp = editor.getTableCellEditorComponent(table, value, true, 0, 1); assertTrue(comp instanceof JTextField); JTextField txt = (JTextField) comp; assertTrue(txt.getText().equals(value)); assertTrue(editor.getCellEditorValue().equals(value)); }