use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.
the class SwingUtil method newField.
@SuppressWarnings("unchecked")
static <T extends Field> T newField(final RecordDefinition recordDefinition, final String fieldName, final boolean editable) {
Field field;
final FieldDefinition fieldDefinition = recordDefinition.getField(fieldName);
if (fieldDefinition == null) {
throw new IllegalArgumentException("Cannot find field " + fieldName);
} else {
final boolean required = fieldDefinition.isRequired();
final int length = fieldDefinition.getLength();
CodeTable codeTable;
if (recordDefinition.getIdFieldNames().contains(fieldName)) {
codeTable = null;
} else {
codeTable = recordDefinition.getCodeTableByFieldName(fieldName);
}
final DataType type = fieldDefinition.getDataType();
int columns = length;
if (columns <= 0) {
columns = 10;
} else if (columns > 50) {
columns = 50;
}
final Class<?> javaClass = type.getJavaClass();
if (codeTable != null) {
if (editable) {
final JComponent component = codeTable.getSwingEditor();
if (component == null) {
field = newComboBox(fieldName, codeTable, required, -1, false);
} else {
field = ((Field) component).clone();
}
} else {
field = new ObjectLabelField(fieldName, columns, codeTable);
}
} else if (!editable) {
final TextField textField = newTextField(fieldName, columns);
textField.setEditable(false);
field = textField;
} else if (Number.class.isAssignableFrom(javaClass)) {
final int scale = fieldDefinition.getScale();
final Number minValue = fieldDefinition.getMinValue();
final Number maxValue = fieldDefinition.getMaxValue();
final NumberTextField numberTextField = new NumberTextField(fieldName, type, length, scale, minValue, maxValue);
field = numberTextField;
} else if (Date.class.isAssignableFrom(javaClass)) {
field = newDateField(fieldName);
} else if (Geometry.class.isAssignableFrom(javaClass)) {
field = new ObjectLabelField(fieldName);
} else {
field = newTextField(fieldName, columns);
}
}
if (field instanceof JTextField) {
final JTextField textField = (JTextField) field;
final int preferedWidth = textField.getPreferredSize().width;
textField.setMinimumSize(new Dimension(preferedWidth, 0));
textField.setMaximumSize(new Dimension(preferedWidth, Integer.MAX_VALUE));
}
((JComponent) field).setFont(FONT);
return (T) field;
}
use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.
the class SwingUtil method setFieldValue.
static void setFieldValue(final JComponent field, final Object value) {
Invoke.later(() -> {
if (field instanceof Field) {
final Field fieldObject = (Field) field;
fieldObject.setFieldValue(value);
} else if (field instanceof JLabel) {
final JLabel label = (JLabel) field;
String string;
if (value == null) {
string = "";
} else {
string = DataTypes.toString(value);
}
label.setText(string);
} else if (field instanceof JTextField) {
final JTextField textField = (JTextField) field;
String string;
if (value == null) {
string = "";
} else {
string = DataTypes.toString(value);
}
textField.setText(string);
} else if (field instanceof JTextArea) {
final JTextArea textField = (JTextArea) field;
String string;
if (value == null) {
string = "";
} else {
string = DataTypes.toString(value);
}
textField.setText(string);
}
final Container parent = field.getParent();
if (parent != null) {
final LayoutManager layout = parent.getLayout();
if (layout != null) {
layout.layoutContainer(parent);
}
field.revalidate();
}
});
}
use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.
the class Form method addNotify.
@Override
public void addNotify() {
super.addNotify();
for (final Entry<String, Field> entry : this.fieldByName.entrySet()) {
final String fieldName = entry.getKey();
final Field field = entry.getValue();
Property.addListener(field, fieldName, this.propertyChangeSetValue);
}
}
use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.
the class Form method getFieldValues.
public Map<String, Object> getFieldValues() {
final Map<String, Object> values = new TreeMap<>();
for (final Entry<String, Field> entry : this.fieldByName.entrySet()) {
final String fieldName = entry.getKey();
final Field field = entry.getValue();
final Object fieldValue = field.getFieldValue();
values.put(fieldName, fieldValue);
}
return values;
}
use of com.revolsys.swing.field.Field in project com.revolsys.open by revolsys.
the class Form method addFields.
protected void addFields(final Component component) {
if (component instanceof Field) {
final Field field = (Field) component;
setField(field);
} else if (component instanceof Container) {
final Container container = (Container) component;
for (final Component childComponent : container.getComponents()) {
addFields(childComponent);
}
}
}
Aggregations