use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.
the class CcddFieldHandler method getFieldDefinitionsFromInformation.
/**
********************************************************************************************
* Get the data field definitions from the field information
*
* @return String list containing the data field definitions
********************************************************************************************
*/
protected List<String[]> getFieldDefinitionsFromInformation() {
// Create storage for the field definitions
List<String[]> definitions = new ArrayList<String[]>();
// Step through each row
for (FieldInformation fieldInfo : fieldInformation) {
// Create storage for a single field definition
String[] defn = new String[FieldsColumn.values().length];
// Store the field definition in the proper order
defn[FieldsColumn.OWNER_NAME.ordinal()] = fieldInfo.getOwnerName();
defn[FieldsColumn.FIELD_NAME.ordinal()] = fieldInfo.getFieldName();
defn[FieldsColumn.FIELD_DESC.ordinal()] = fieldInfo.getDescription();
defn[FieldsColumn.FIELD_TYPE.ordinal()] = fieldInfo.getInputType().getInputName();
defn[FieldsColumn.FIELD_SIZE.ordinal()] = String.valueOf(fieldInfo.getSize());
defn[FieldsColumn.FIELD_REQUIRED.ordinal()] = String.valueOf(fieldInfo.isRequired());
defn[FieldsColumn.FIELD_APPLICABILITY.ordinal()] = fieldInfo.getApplicabilityType().getApplicabilityName();
defn[FieldsColumn.FIELD_VALUE.ordinal()] = fieldInfo.getValue();
// Add the field definition to the list
definitions.add(defn);
}
return definitions;
}
use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.
the class CcddFieldHandler method getFieldEditorDefinition.
/**
********************************************************************************************
* Get the array of data field definitions for the data field editor
*
* @return Object array containing the data field definitions used by the data field editor
********************************************************************************************
*/
protected Object[][] getFieldEditorDefinition() {
List<Object[]> definitions = new ArrayList<Object[]>();
// Step through each row
for (FieldInformation fieldInfo : fieldInformation) {
// Create storage for a single field definition
Object[] row = new Object[FieldEditorColumnInfo.values().length];
// Store the field definition in the proper order
row[FieldEditorColumnInfo.NAME.ordinal()] = fieldInfo.getFieldName();
row[FieldEditorColumnInfo.DESCRIPTION.ordinal()] = fieldInfo.getDescription();
row[FieldEditorColumnInfo.INPUT_TYPE.ordinal()] = fieldInfo.getInputType().getInputName();
row[FieldEditorColumnInfo.SIZE.ordinal()] = fieldInfo.getSize();
row[FieldEditorColumnInfo.REQUIRED.ordinal()] = fieldInfo.isRequired();
row[FieldEditorColumnInfo.APPLICABILITY.ordinal()] = fieldInfo.getApplicabilityType().getApplicabilityName();
row[FieldEditorColumnInfo.VALUE.ordinal()] = fieldInfo.getValue();
// Add the field definition to the list
definitions.add(row);
}
return definitions.toArray(new Object[0][0]);
}
use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.
the class CcddFieldHandler method updateField.
/**
********************************************************************************************
* Update an existing data field's information
*
* @param updateInfo
* updated field information used to replace the existing field information
*
* @return true if the a matching owner and field exists for the provided field information
* update
********************************************************************************************
*/
protected boolean updateField(FieldInformation updateInfo) {
boolean isUpdate = false;
// Get the reference to the field information for the specified owner/field combination
FieldInformation fieldInfo = getFieldInformationByName(updateInfo.getOwnerName(), updateInfo.getFieldName());
// one
if (fieldInfo != null && (!fieldInfo.getDescription().equals(updateInfo.getDescription()) || !fieldInfo.getInputType().equals(updateInfo.getInputType()) || fieldInfo.getSize() != updateInfo.getSize() || fieldInfo.isRequired() != updateInfo.isRequired() || !fieldInfo.getValue().equals(updateInfo.getValue()))) {
// Get the position of the field within the list
int index = fieldInformation.indexOf(fieldInfo);
// Remove the existing field from the list
fieldInformation.remove(fieldInfo);
// Add the updated field information to the list at the same position as the old field
fieldInformation.add(index, updateInfo);
// Set the flag to indicate a match exists
isUpdate = true;
}
return isUpdate;
}
use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.
the class CcddInputFieldPanelHandler method createDataFieldPanel.
/**
********************************************************************************************
* Create the data fields for display in the description and data field panel
*
* @param undoable
* true if the change(s) to the data fields should be stored for possible undo/redo
* operations; false to not store the changes
********************************************************************************************
*/
protected void createDataFieldPanel(boolean undoable) {
maxFieldWidth = 0;
// Set the preferred size so that the layout manager uses its default sizing
fieldPnlHndlrOwner.setPreferredSize(null);
// Check if the data fields are already displayed
if (fieldPnl != null) {
// Remove the existing data fields
inputPnl.remove(fieldPnl);
}
// Check if this is a data table
if (isDataTable) {
// Build the data field information so that only applicable fields are displayed
dataFieldHandler.buildFieldInformation(((CcddTableEditorHandler) this).getTableInformation().getTablePath(), ((CcddTableEditorHandler) this).getTableInformation().isRootStructure(), false);
}
// Check if any data fields exist
if (dataFieldHandler.getFieldInformation() != null && !dataFieldHandler.getFieldInformation().isEmpty()) {
// Create a panel to contain the data fields. As the editor is resized the field panel
// is resized to contain the data fields, wrapping them to new lines as needed
fieldPnl = new JPanel(new WrapLayout(FlowLayout.LEADING));
// Adjust the border to align the first field with the description label
fieldPnl.setBorder(BorderFactory.createEmptyBorder(-ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), -ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, 0));
// Step through each data field
for (final FieldInformation fieldInfo : dataFieldHandler.getFieldInformation()) {
switch(fieldInfo.getInputType().getInputFormat()) {
case PAGE_FORMAT:
switch(fieldInfo.getInputType()) {
case BREAK:
// Create a text field for the separator so it can be handled like
// other fields
fieldInfo.setInputFld(undoHandler.new UndoableTextField());
// Add a vertical separator to the field panel
fieldPnl.add(new JSeparator(SwingConstants.VERTICAL));
break;
case SEPARATOR:
// Create a text field for the separator so it can be handled like
// other fields
fieldInfo.setInputFld(undoHandler.new UndoableTextField());
// Add a horizontal separator to the field panel
fieldPnl.add(new JSeparator());
break;
default:
break;
}
break;
case BOOLEAN:
// Create the data field check box
fieldInfo.setInputFld(undoHandler.new UndoableCheckBox(fieldInfo.getFieldName(), Boolean.valueOf(fieldInfo.getValue())));
UndoableCheckBox booleanCb = (UndoableCheckBox) fieldInfo.getInputFld();
booleanCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
booleanCb.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
// Set the check box's name so that the undo handler can identify the check
// box, even if it's destroyed and recreated
booleanCb.setName(fieldInfo.getOwnerName() + DATA_FIELD_IDENTIFIER_SEPARATOR + fieldInfo.getFieldName());
// Adjust the left and right padding around the check box so that it is
// spaced the same as a text field data field
booleanCb.setBorder(BorderFactory.createEmptyBorder(0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), 0, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()));
// Check if a description exists for this field
if (!fieldInfo.getDescription().isEmpty()) {
// Set the description as the tool tip text for this check box
booleanCb.setToolTipText(CcddUtilities.wrapText(fieldInfo.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
}
// And the check box to the field panel
fieldPnl.add(booleanCb);
// Store this check box's width if it is the largest data field width
maxFieldWidth = Math.max(maxFieldWidth, booleanCb.getPreferredSize().width);
break;
default:
final JTextComponent inputFld;
// Create a panel for a single label and text field pair. This is necessary
// so that the two will stay together if line wrapping occurs due to a
// window size change
JPanel singleFldPnl = new JPanel(new FlowLayout(FlowLayout.LEADING, ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing() / 4));
singleFldPnl.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
// Create the data field label
JLabel fieldLbl = new JLabel(fieldInfo.getFieldName());
fieldLbl.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
fieldLbl.setForeground(ModifiableColorInfo.SPECIAL_LABEL_TEXT.getColor());
singleFldPnl.add(fieldLbl);
// Check if the input type is for multi-line text
if (fieldInfo.getInputType().equals(InputDataType.TEXT_MULTI)) {
// Create the data field input field as a text area, which allows new
// line characters which cause the field to be displayed in multiple
// rows
fieldInfo.setInputFld(undoHandler.new UndoableTextArea(fieldInfo.getValue(), 1, fieldInfo.getSize()));
inputFld = (UndoableTextArea) fieldInfo.getInputFld();
} else // The input type is one other than for multi-line text
{
// Create the data field input field as a text field, which allows a
// single rows
fieldInfo.setInputFld(undoHandler.new UndoableTextField(fieldInfo.getValue(), fieldInfo.getSize()));
inputFld = (UndoableTextField) fieldInfo.getInputFld();
}
inputFld.setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
inputFld.setEditable(true);
inputFld.setBorder(border);
inputFld.setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
inputFld.setBackground(fieldInfo.getValue().isEmpty() && fieldInfo.isRequired() ? ModifiableColorInfo.REQUIRED_BACK.getColor() : ModifiableColorInfo.INPUT_BACK.getColor());
// Set the text field's name so that the undo handler can identify the text
// field, even if it's destroyed and recreated
inputFld.setName(fieldInfo.getOwnerName() + DATA_FIELD_IDENTIFIER_SEPARATOR + fieldInfo.getFieldName());
// Check if a description exists for this field
if (!fieldInfo.getDescription().isEmpty()) {
// Set the description as the tool tip text for this text field
inputFld.setToolTipText(CcddUtilities.wrapText(fieldInfo.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
}
// Add the data field to the single field panel
singleFldPnl.add(inputFld);
// And the single field to the field panel
fieldPnl.add(singleFldPnl);
// Store this field's width if it is the largest data field width
maxFieldWidth = Math.max(maxFieldWidth, singleFldPnl.getPreferredSize().width);
// Create an input field verifier for the data field
inputFld.setInputVerifier(new InputVerifier() {
// Storage for the last valid value entered; used to restore the data
// field value if an invalid value is entered. Initialize to the value
// at the time the field is created
String lastValid = inputFld.getText();
/**
********************************************************************
* Verify the contents of a the data field
********************************************************************
*/
@Override
public boolean verify(JComponent input) {
boolean isValid = true;
// Get the data field reference to shorten subsequent calls
JTextComponent inFld = (JTextComponent) input;
// Get the data field contents
String inputTxt = inFld.getText();
// trailing white space characters
if (fieldInfo.getInputType() != InputDataType.TEXT_WHT_SPC && fieldInfo.getInputType() != InputDataType.TEXT_MULTI_WHT_SPC) {
// Remove leading and trailing white space characters
inputTxt = inputTxt.trim();
}
// Check if the field contains an illegal character
if (!fieldInfo.getInputType().getInputMatch().isEmpty() && !inputTxt.isEmpty() && !inputTxt.matches(fieldInfo.getInputType().getInputMatch())) {
// Inform the user that the data field contents is invalid
new CcddDialogHandler().showMessageDialog(fieldPnlHndlrOwner, "<html><b>Invalid characters in field '</b>" + fieldInfo.getFieldName() + "<b>'; characters consistent with input type '" + fieldInfo.getInputType().getInputName() + "' expected", "Invalid " + fieldInfo.getInputType().getInputName(), JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
// redrawn correctly
if (fieldPnlHndlrOwner instanceof CcddFrameHandler) {
((CcddFrameHandler) fieldPnlHndlrOwner).setControlsEnabled(false);
((CcddFrameHandler) fieldPnlHndlrOwner).setControlsEnabled(true);
} else if (fieldPnlHndlrOwner instanceof CcddDialogHandler) {
((CcddDialogHandler) fieldPnlHndlrOwner).setControlsEnabled(false);
((CcddDialogHandler) fieldPnlHndlrOwner).setControlsEnabled(true);
}
// Check if the data field is a text field
if (input instanceof UndoableTextField) {
// Restore the previous value in the data field
((UndoableTextField) inFld).setText(lastValid, false);
} else // Check if the data field is a text area (multi-line)
if (input instanceof UndoableTextArea) {
// Restore the previous value in the data field
((UndoableTextArea) inFld).setText(lastValid);
}
// Set the flag to indicate an invalid value was entered
isValid = false;
} else // The input is valid
{
// Store the 'cleaned' text back into the text field. For
// numeric types, reformat the input value
inFld.setText(fieldInfo.getInputType().formatInput(inputTxt));
fieldInfo.setValue(inFld.getText());
// Store the new value as the last valid value
lastValid = inFld.getText();
// Set the text field background color. If the field is empty
// and is flagged as required then set the background to
// indicate a value should be supplied
setFieldBackground(fieldInfo);
}
return isValid;
}
});
break;
}
}
// Check that at least one field exists
if (fieldPnl.getComponentCount() != 0) {
// Add the data field panel to the dialog
inputPnl.add(fieldPnl, gbc);
}
}
// Check if this is a data table
if (isDataTable) {
// Build the data field information so that all fields are included
dataFieldHandler.buildFieldInformation(((CcddTableEditorHandler) this).getTableInformation().getTablePath(), ((CcddTableEditorHandler) this).getTableInformation().isRootStructure(), true);
}
// Check if the data field panel change should be put in the undo/redo stack
if (undoable) {
// Store the field information in the undo handler in case the update needs to be
// undone
undoFieldPnl.addDataFieldEdit(this, dataFieldHandler.getFieldInformationCopy());
}
// Force the owner of the editor panel to redraw so that changes to the fields are
// displayed and the owner's size is adjusted
fieldPnlHndlrOwner.revalidate();
fieldPnlHndlrOwner.repaint();
}
use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.
the class CcddInputFieldPanelHandler method clearFieldValues.
/**
********************************************************************************************
* Clear the values from all fields
********************************************************************************************
*/
protected void clearFieldValues() {
// Disable automatically ending the edit sequence. This allows all of the cleared fields to
// be grouped into a single sequence so that if undone, all fields are restored
undoHandler.setAutoEndEditSequence(false);
for (FieldInformation fieldInfo : dataFieldHandler.getFieldInformation()) {
// Check if this is a boolean input (check box) data field
if (fieldInfo.getInputType().getInputFormat() == InputTypeFormat.BOOLEAN) {
// Set the field value to 'false'
fieldInfo.setValue("false");
// Set the check box
((UndoableCheckBox) fieldInfo.getInputFld()).setSelected(false);
} else // Not a boolean input (check box) data field
{
// Get the reference to the data field
JTextComponent inputFld = (JTextComponent) fieldInfo.getInputFld();
// Clear the field value
fieldInfo.setValue("");
inputFld.setText("");
// Set the text field background color. If the field is flagged as required then
// set the background to indicate a value should be supplied
setFieldBackground(fieldInfo);
}
}
// Re-enable automatic edit sequence ending, then end the edit sequence to group the
// cleared fields
undoHandler.setAutoEndEditSequence(true);
undoManager.endEditSequence();
}
Aggregations