Search in sources :

Example 31 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddGroupManagerDialog method copyGroup.

/**
 ********************************************************************************************
 * Copy the selected group
 ********************************************************************************************
 */
private void copyGroup() {
    // Get the selected group(s)
    String[] selected = groupTree.getTopLevelSelectedNodeNames();
    // Check that a single node is selected in the group tree
    if (selected.length == 1) {
        // Get the group information for the selected group
        GroupInformation groupInfo = groupHandler.getGroupInformationByName(selected[0]);
        // Create a panel to contain the dialog components
        JPanel dialogPnl = new JPanel(new GridBagLayout());
        // Create the group copying dialog label and field
        addGroupNameField("Copy '" + selected[0] + "' to:", selected[0] + "_copy", dialogPnl);
        // Create the group copying dialog
        CcddDialogHandler groupDlg = new CcddDialogHandler() {

            /**
             ********************************************************************************
             * Verify that the dialog content is valid
             *
             * @return true if the input values are valid
             ********************************************************************************
             */
            @Override
            protected boolean verifySelection() {
                return verifyGroupName(this);
            }
        };
        // Display the group copying dialog
        if (groupDlg.showOptionsDialog(groupMgr, dialogPnl, "Copy Group", DialogOption.COPY_OPTION, true) == OK_BUTTON) {
            // Disable automatically ending the edit sequence. This allows all of the copied
            // group's edits to be grouped into a single sequence so that if undone, all of the
            // group's edits are restored together
            undoHandler.setAutoEndEditSequence(false);
            // Copy the group node in the group tree
            groupTree.copyNodeTree(groupInfo.getName(), groupNameFld.getText(), groupInfo);
            // Copy the target group's data fields to the copy of the group
            groupHandler.getGroupInformationByName(groupNameFld.getText()).setFieldInformation(CcddFieldHandler.getFieldInformationCopy(groupInfo.getFieldInformation()));
            // Step through each data field in the copied group
            for (FieldInformation fieldInfo : groupHandler.getGroupInformationByName(groupNameFld.getText()).getFieldInformation()) {
                // Set the data field owner to the copy's group name
                fieldInfo.setOwnerName(CcddFieldHandler.getFieldGroupName(groupNameFld.getText()));
            }
            // Update the group dialog's change indicator
            updateChangeIndicator();
            // Re-enable automatic edit sequence ending, then end the edit sequence to group
            // the renamed group's edits
            undoHandler.setAutoEndEditSequence(true);
            undoManager.endEditSequence();
        }
    }
}
Also used : JPanel(javax.swing.JPanel) GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) GridBagLayout(java.awt.GridBagLayout) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 32 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddScriptDataAccessHandler method getDataFieldNames.

/**
 ********************************************************************************************
 * Get the name(s) of the data field(s) associated with the specified owner
 *
 * @param ownerName
 *            name of the table type to which the field is a member
 *
 * @return Array of the data field names associated with the specified owner; returns an empty
 *         array if the owner name is invalid or the owner has no data fields
 ********************************************************************************************
 */
private String[] getDataFieldNames(String ownerName) {
    List<String> fieldNames = new ArrayList<String>();
    // Build the field information for this owner
    fieldHandler.buildFieldInformation(ownerName);
    // Step through each data field associated with the owner
    for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
        // Add the field name to the list
        fieldNames.add(fieldInfo.getFieldName());
    }
    return fieldNames.toArray(new String[0]);
}
Also used : ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 33 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddScriptDataAccessHandler method getGroupFields.

/**
 ********************************************************************************************
 * Get an array containing the data field information for the specified group
 *
 * @param groupName
 *            group name
 *
 * @return Array containing the data field information for the specified group; an empty array
 *         if the group has no data fields, or the group doesn't exist. The array in is the
 *         format: field name, description, size, input type, required (true or false),
 *         applicability, value[,...]
 ********************************************************************************************
 */
public String[][] getGroupFields(String groupName) {
    List<String[]> groupFields = new ArrayList<String[]>();
    // Get a reference to the group's information
    GroupInformation groupInfo = groupHandler.getGroupInformationByName(groupName);
    // Check if the group exists
    if (groupInfo != null) {
        // Step through each data field belonging to the group
        for (FieldInformation fieldInfo : groupInfo.getFieldInformation()) {
            // Add the data field information to the list
            groupFields.add(new String[] { fieldInfo.getFieldName(), fieldInfo.getDescription(), Integer.toString(fieldInfo.getSize()), fieldInfo.getInputType().getInputName(), Boolean.toString(fieldInfo.isRequired()), fieldInfo.getApplicabilityType().getApplicabilityName(), fieldInfo.getValue() });
        }
    }
    return groupFields.toArray(new String[0][0]);
}
Also used : GroupInformation(CCDD.CcddClassesDataTable.GroupInformation) ArrayList(java.util.ArrayList) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 34 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddScriptDataAccessHandler method getDataFieldDescription.

/**
 ********************************************************************************************
 * Get the description of the data field for the specified owner's specified data field
 *
 * @param ownerName
 *            name of the data field owner (table name, including the path if this table
 *            references a structure, group name, or table type name)
 *
 * @param fieldName
 *            data field name
 *
 * @return Data field description; returns a blank if the owner name or field name is invalid
 ********************************************************************************************
 */
private String getDataFieldDescription(String ownerName, String fieldName) {
    String fieldDescription = "";
    // Get the reference to the data field information for the requested owner and field names
    FieldInformation fieldInfo = fieldHandler.getFieldInformationByName(ownerName, fieldName);
    // Check if a field for this owner exists
    if (fieldInfo != null) {
        // Get the field description
        fieldDescription = fieldInfo.getDescription();
    }
    return fieldDescription;
}
Also used : FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Example 35 with FieldInformation

use of CCDD.CcddClassesDataTable.FieldInformation in project CCDD by nasa.

the class CcddWebDataAccessHandler method getTableFields.

/**
 ********************************************************************************************
 * Get the data field information for the specified table, or for all tables if no table name
 * is provided
 *
 * @param tableName
 *            table name and path in the format rootTable[,dataType1.variable1[,...]]. If blank
 *            then every data table's data fields are returned
 *
 * @param checkExists
 *            true to check if the specified table exists in the project database
 *
 * @return JSON encoded string containing the specified table's data fields; null if the table
 *         doesn't exist or if the project database contains no data tables
 *
 * @throws CCDDException
 *             If an error occurs while parsing the table data field data
 ********************************************************************************************
 */
@SuppressWarnings("unchecked")
private String getTableFields(String tableName, boolean checkExists) throws CCDDException {
    String response = null;
    // Check if no table name is provided (i.e., get all tables' fields)
    if (tableName.isEmpty()) {
        // Check if at least one table exists
        if (dbTable.queryTableList(ccddMain.getMainFrame()).length != 0) {
            List<String> tableNames = new ArrayList<String>();
            // Step through the data fields
            for (FieldInformation fieldInfo : fieldHandler.getFieldInformation()) {
                // table type or group data field
                if (!tableNames.contains(fieldInfo.getOwnerName()) && !fieldInfo.getOwnerName().startsWith(TYPE_DATA_FIELD_IDENT) && !fieldInfo.getOwnerName().startsWith(GROUP_DATA_FIELD_IDENT)) {
                    // Store the table name in the list
                    tableNames.add(fieldInfo.getOwnerName());
                }
            }
            JSONArray responseJA = new JSONArray();
            JSONParser parser = new JSONParser();
            response = "";
            // Step through the list of tables with data fields
            for (String name : tableNames) {
                try {
                    // Get the fields for this table as a JSON string, then format it as a JSON
                    // object so that is can be added to the response array. This is needed to
                    // get the brackets and commas in the JSON formatted string correct
                    responseJA.add(parser.parse(getTableFields(name, false)));
                } catch (ParseException pe) {
                    throw new CCDDException("error parsing table data fields");
                }
            }
            // Add the table fields to the response
            response = responseJA.toString();
        }
    } else // table exists in the database
    if (!checkExists || dbTable.isTableExists(tableName, ccddMain.getMainFrame())) {
        // Add the table name and data field information to the output
        JSONObject tableNameAndFields = new JSONObject();
        tableNameAndFields.put(JSONTags.TABLE_NAME.getTag(), tableName);
        tableNameAndFields = jsonHandler.getDataFields(tableName, JSONTags.TABLE_FIELD.getTag(), tableNameAndFields);
        response = tableNameAndFields.toString();
    }
    return response;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) JSONObject(org.json.simple.JSONObject) ArrayList(java.util.ArrayList) JSONArray(org.json.simple.JSONArray) JSONParser(org.json.simple.parser.JSONParser) ParseException(org.json.simple.parser.ParseException) FieldInformation(CCDD.CcddClassesDataTable.FieldInformation)

Aggregations

FieldInformation (CCDD.CcddClassesDataTable.FieldInformation)35 ArrayList (java.util.ArrayList)16 GroupInformation (CCDD.CcddClassesDataTable.GroupInformation)7 GridBagLayout (java.awt.GridBagLayout)4 Point (java.awt.Point)4 JPanel (javax.swing.JPanel)4 CCDDException (CCDD.CcddClassesDataTable.CCDDException)3 TableInformation (CCDD.CcddClassesDataTable.TableInformation)3 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)3 UndoableCheckBox (CCDD.CcddUndoHandler.UndoableCheckBox)3 TableTypeDefinition (CCDD.CcddClassesDataTable.TableTypeDefinition)2 Variable (CCDD.CcddClassesDataTable.Variable)2 DefaultApplicationField (CCDD.CcddConstants.DefaultApplicationField)2 InputDataType (CCDD.CcddConstants.InputDataType)2 UndoableTextField (CCDD.CcddUndoHandler.UndoableTextField)2 Component (java.awt.Component)2 GridBagConstraints (java.awt.GridBagConstraints)2 JComponent (javax.swing.JComponent)2 JLabel (javax.swing.JLabel)2 JTextArea (javax.swing.JTextArea)2