Search in sources :

Example 11 with FileEnvVar

use of CCDD.CcddClassesComponent.FileEnvVar in project CCDD by nasa.

the class CcddPatchHandler method updateTableTypesTable.

/**
 ********************************************************************************************
 * Update the internal table __types to the new name __table_types, delete the primitive_only
 * column, and add the structure allowed and pointer allowed columns. If successful, the
 * original table (__types) is renamed, preserving the original information and preventing
 * subsequent conversion attempts. The project database is first backed up to the file
 * <projectName>_<timeStamp>.dbu. Older versions of CCDD are not compatible with the project
 * database after applying this patch
 *
 * @throws CCDDException
 *             If the user elects to not install the patch or an error occurs while applying
 *             the patch
 ********************************************************************************************
 */
private void updateTableTypesTable() throws CCDDException {
    CcddDbTableCommandHandler dbTable = ccddMain.getDbTableCommandHandler();
    // Check if the old table exists
    if (dbTable.isTableExists("__types", ccddMain.getMainFrame())) {
        // Check if the user elects to not apply the patch
        if (new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Apply patch to update the table types " + "table?<br><br></b>Creates the new " + "__table_types table from the old __types " + "table.<br><b><i>Older versions of CCDD " + "will be incompatible with this project " + "database after applying the patch", "Apply Patch #01262017", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) != OK_BUTTON) {
            throw new CCDDException("user elected to not install patch (#01262017)");
        }
        CcddDbControlHandler dbControl = ccddMain.getDbControlHandler();
        CcddDbCommandHandler dbCommand = ccddMain.getDbCommandHandler();
        CcddEventLogDialog eventLog = ccddMain.getSessionEventLog();
        CcddTableTypeHandler tableTypeHandler = ccddMain.getTableTypeHandler();
        try {
            // Back up the project database before applying the patch
            dbControl.backupDatabase(dbControl.getDatabaseName(), new FileEnvVar(ModifiablePathInfo.DATABASE_BACKUP_PATH.getPath() + File.separator + dbControl.getDatabaseName() + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + FileExtension.DBU.getExtension()));
            // Create lists to contain the old and new table types table items
            List<String[]> oldTableData = new ArrayList<String[]>();
            List<String[]> newTableData = new ArrayList<String[]>();
            // Read the contents of the old table types table
            ResultSet infoData = dbCommand.executeDbQuery("SELECT * FROM __types ORDER BY OID;", ccddMain.getMainFrame());
            // Step through each of the query results
            while (infoData.next()) {
                // Create an array to contain the column values
                String[] columnValues = new String[infoData.getMetaData().getColumnCount()];
                // Step through each column in the row
                for (int column = 0; column < infoData.getMetaData().getColumnCount(); column++) {
                    // Add the column value to the array. Note that the first column's index in
                    // the database is 1, not 0
                    columnValues[column] = infoData.getString(column + 1);
                    // Check if the value is null
                    if (columnValues[column] == null) {
                        // Replace the null with a blank
                        columnValues[column] = "";
                    }
                }
                // Add the row data to the list
                oldTableData.add(columnValues);
            }
            infoData.close();
            // Indicate in the log that the old data successfully loaded
            eventLog.logEvent(SUCCESS_MSG, "__types retrieved");
            // Step through the old table types column definitions
            for (String[] oldColumnDefn : oldTableData) {
                boolean isFound = false;
                // Create storage for the new column definition
                String[] newColumnDefn = new String[InternalTable.TABLE_TYPES.getNumColumns()];
                // Step through each of the old columns (the new table has one extra column)
                for (int index = 0; index < TableTypesColumn.values().length - 1; index++) {
                    // Copy the old columns definition to the new column definition
                    newColumnDefn[index] = oldColumnDefn[index];
                }
                // Get the default type definition for this table type name
                TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(oldColumnDefn[TableTypesColumn.TYPE_NAME.ordinal()]);
                // Check if the type exists in the default definitions
                if (typeDefn != null) {
                    // Get the index of the column
                    int column = typeDefn.getColumnIndexByDbName(oldColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()]);
                    // Check if the column exists in the default type definition
                    if (column != -1) {
                        // Use the default definition to set the structure and pointer allowed
                        // flags
                        newColumnDefn[TableTypesColumn.STRUCTURE_ALLOWED.ordinal()] = typeDefn.isStructureAllowed()[column] ? "t" : "f";
                        newColumnDefn[TableTypesColumn.POINTER_ALLOWED.ordinal()] = typeDefn.isPointerAllowed()[column] ? "t" : "f";
                        isFound = true;
                    }
                }
                // Check if this column isn't in the default column definitions
                if (!isFound) {
                    // Assume that this column is valid for a structures and pointers
                    newColumnDefn[TableTypesColumn.STRUCTURE_ALLOWED.ordinal()] = "t";
                    newColumnDefn[TableTypesColumn.POINTER_ALLOWED.ordinal()] = "t";
                }
                // Add the column definition to the list
                newTableData.add(newColumnDefn);
            }
            // Delete the default column definitions
            tableTypeHandler.getTypeDefinitions().clear();
            // Step through the updated table types column definitions
            for (String[] newColumnDefn : newTableData) {
                // Get the type definition associated with this column
                TypeDefinition typeDefn = tableTypeHandler.getTypeDefinition(newColumnDefn[TableTypesColumn.TYPE_NAME.ordinal()]);
                // Check if the type is not defined
                if (typeDefn == null) {
                    // Create the type and add it to the list. THis creates the primary key and
                    // row index columns
                    typeDefn = tableTypeHandler.createTypeDefinition(newColumnDefn[TableTypesColumn.TYPE_NAME.ordinal()], new String[0][0], newColumnDefn[TableTypesColumn.COLUMN_DESCRIPTION.ordinal()]);
                }
                // these were created previously
                if (!newColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()].equals(DefaultColumn.PRIMARY_KEY.getDbName()) && !newColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()].equals(DefaultColumn.ROW_INDEX.getDbName())) {
                    // Add the column names, description, input type, and flags to the type
                    // definition
                    typeDefn.addColumn(Integer.parseInt(newColumnDefn[TableTypesColumn.INDEX.ordinal()].toString()), newColumnDefn[TableTypesColumn.COLUMN_NAME_DB.ordinal()].toString(), newColumnDefn[TableTypesColumn.COLUMN_NAME_VISIBLE.ordinal()].toString(), newColumnDefn[TableTypesColumn.COLUMN_DESCRIPTION.ordinal()].toString(), InputDataType.getInputTypeByName(newColumnDefn[TableTypesColumn.INPUT_TYPE.ordinal()].toString()), newColumnDefn[TableTypesColumn.ROW_VALUE_UNIQUE.ordinal()].equals("t") ? true : false, newColumnDefn[TableTypesColumn.COLUMN_REQUIRED.ordinal()].equals("t") ? true : false, newColumnDefn[TableTypesColumn.STRUCTURE_ALLOWED.ordinal()].equals("t") ? true : false, newColumnDefn[TableTypesColumn.POINTER_ALLOWED.ordinal()].equals("t") ? true : false);
                }
            }
            // Store the updated table type definitions in the project database and change the
            // old table types table name so that the conversion doesn't take place again
            dbCommand.executeDbCommand(dbTable.storeTableTypesInfoTableCommand() + "ALTER TABLE __types RENAME TO __types_backup;", ccddMain.getMainFrame());
            // Inform the user that converting the table types completed
            eventLog.logEvent(EventLogMessageType.SUCCESS_MSG, "Table types conversion complete");
            // Reopen the database
            dbControl.openDatabase(dbControl.getProjectName());
        } catch (Exception e) {
            // Inform the user that converting the table types table failed
            eventLog.logFailEvent(ccddMain.getMainFrame(), "Cannot convert table types table to new format; cause '" + e.getMessage() + "'", "<html><b>Cannot convert table types table to new " + "format (project database will be closed)");
            throw new CCDDException();
        }
    }
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) ArrayList(java.util.ArrayList) CCDDException(CCDD.CcddClassesDataTable.CCDDException) TypeDefinition(CCDD.CcddTableTypeHandler.TypeDefinition) ResultSet(java.sql.ResultSet) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with FileEnvVar

use of CCDD.CcddClassesComponent.FileEnvVar in project CCDD by nasa.

the class CcddPatchHandler method updateFieldApplicability.

/**
 ********************************************************************************************
 * Update the data fields table applicability column to change "Parents only" to "Roots only".
 * Older versions of CCDD are not compatible with the project database after applying this
 * patch
 *
 * @throws CCDDException
 *             If the user elects to not install the patch or an error occurs while applying
 *             the patch
 ********************************************************************************************
 */
private void updateFieldApplicability() throws CCDDException {
    CcddEventLogDialog eventLog = ccddMain.getSessionEventLog();
    CcddDbControlHandler dbControl = ccddMain.getDbControlHandler();
    try {
        CcddDbCommandHandler dbCommand = ccddMain.getDbCommandHandler();
        // Read the contents of the data field table's applicability column
        ResultSet fieldData = dbCommand.executeDbQuery("SELECT * FROM " + InternalTable.FIELDS.getTableName() + " WHERE " + FieldsColumn.FIELD_APPLICABILITY.getColumnName() + " = 'Parents only';", ccddMain.getMainFrame());
        // Check if the patch hasn't already been applied
        if (fieldData.next()) {
            // Check if the user elects to not apply the patch
            if (new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Apply patch to update the data " + "fields table?<br><br></b>Changes " + "data field applicability 'Parents " + "only' to 'Roots only'.<br><b><i>Older " + "versions of CCDD are imcompatible " + "with this project database after " + "applying the patch", "Apply Patch #09272017", JOptionPane.QUESTION_MESSAGE, DialogOption.OK_CANCEL_OPTION) != OK_BUTTON) {
                fieldData.close();
                throw new CCDDException("user elected to not install patch (#09272017)");
            }
            fieldData.close();
            // Back up the project database before applying the patch
            dbControl.backupDatabase(dbControl.getDatabaseName(), new FileEnvVar(ModifiablePathInfo.DATABASE_BACKUP_PATH.getPath() + File.separator + dbControl.getDatabaseName() + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(Calendar.getInstance().getTime()) + FileExtension.DBU.getExtension()));
            // Update the data fields table
            dbCommand.executeDbCommand("UPDATE " + InternalTable.FIELDS.getTableName() + " SET " + FieldsColumn.FIELD_APPLICABILITY.getColumnName() + " = '" + ApplicabilityType.ROOT_ONLY.getApplicabilityName() + "' WHERE " + FieldsColumn.FIELD_APPLICABILITY.getColumnName() + " = 'Parents only';", ccddMain.getMainFrame());
            // Inform the user that updating the database data fields table completed
            eventLog.logEvent(EventLogMessageType.SUCCESS_MSG, "Project '" + dbControl.getProjectName() + "' data fields table conversion complete");
        }
    } catch (Exception e) {
        // Inform the user that converting the data fields table failed
        eventLog.logFailEvent(ccddMain.getMainFrame(), "Cannot convert project '" + dbControl.getProjectName() + "' data fields table to new format; cause '" + e.getMessage() + "'", "<html><b>Cannot convert project '" + dbControl.getProjectName() + "' data fields table to new format " + "(project database will be closed)");
        throw new CCDDException();
    }
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) ResultSet(java.sql.ResultSet) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) SimpleDateFormat(java.text.SimpleDateFormat) CCDDException(CCDD.CcddClassesDataTable.CCDDException)

Example 13 with FileEnvVar

use of CCDD.CcddClassesComponent.FileEnvVar in project CCDD by nasa.

the class CcddPreferencesDialog method addPathTab.

/**
 ********************************************************************************************
 * Add the path update tab to the tabbed pane
 ********************************************************************************************
 */
private void addPathTab() {
    // Set the initial layout manager characteristics
    GridBagConstraints gbc = new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2, ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2), 0, 0);
    // Create a border for the input fields
    Border border = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED, Color.LIGHT_GRAY, Color.GRAY), BorderFactory.createEmptyBorder(ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing(), ModifiableSpacingInfo.INPUT_FIELD_PADDING.getSpacing()));
    // Create storage for the description and input field representing each modifiable path
    JLabel[] pathLbl = new JLabel[ModifiablePathInfo.values().length];
    JButton[] pathBtn = new JButton[ModifiablePathInfo.values().length];
    pathFld = new JTextField[ModifiablePathInfo.values().length];
    // Create a panel to contain the path components
    JPanel innerPathPnl = new JPanel(new GridBagLayout());
    innerPathPnl.setBorder(emptyBorder);
    // Use an outer panel so that the components can be forced to the top of the tab area
    JPanel pathPnl = new JPanel(new BorderLayout());
    pathPnl.setBorder(emptyBorder);
    pathPnl.add(innerPathPnl, BorderLayout.PAGE_START);
    // Create a scroll pane in which to display the path labels and fields
    JScrollPane pathScrollPane = new JScrollPane(pathPnl);
    pathScrollPane.setBorder(emptyBorder);
    pathScrollPane.setViewportBorder(emptyBorder);
    // Add the path update tab to the tabbed pane
    tabbedPane.addTab(PATH, null, pathScrollPane, "Change program paths");
    // Create a listener for the path selection buttons
    ActionListener defaultListener = new ActionListener() {

        /**
         ************************************************************************************
         * Update the path to the selection
         ************************************************************************************
         */
        @Override
        public void actionPerformed(ActionEvent ae) {
            // Get the index of the path field array, which is stored as the button's name
            int index = Integer.valueOf(((JButton) ae.getSource()).getName());
            // Allow the user to select the script file path + name
            FileEnvVar[] pathFile = new CcddDialogHandler().choosePathFile(ccddMain, CcddPreferencesDialog.this, "Select Path", pathFld[index].getText(), DialogOption.OK_CANCEL_OPTION);
            // Check if a path is selected
            if (pathFile != null && pathFile[0] != null) {
                // Display the file name in the path name field
                pathFld[index].setText(pathFile[0].getAbsolutePathWithEnvVars());
            }
        }
    };
    int index = 0;
    // Step through each modifiable path
    for (final ModifiablePathInfo modPath : ModifiablePathInfo.values()) {
        // Create the path label and input field
        pathLbl[index] = new JLabel(modPath.getName());
        pathLbl[index].setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
        pathLbl[index].setToolTipText(CcddUtilities.wrapText(modPath.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
        innerPathPnl.add(pathLbl[index], gbc);
        pathFld[index] = new JTextField(String.valueOf(modPath.getPath()), 40);
        pathFld[index].setFont(ModifiableFontInfo.INPUT_TEXT.getFont());
        pathFld[index].setForeground(ModifiableColorInfo.INPUT_TEXT.getColor());
        pathFld[index].setBackground(ModifiableColorInfo.INPUT_BACK.getColor());
        pathFld[index].setBorder(border);
        pathFld[index].setName(modPath.getPreferenceKey());
        pathFld[index].setToolTipText(CcddUtilities.wrapText(modPath.getDescription(), ModifiableSizeInfo.MAX_TOOL_TIP_LENGTH.getSize()));
        // Add the path field to the path panel
        gbc.gridx++;
        innerPathPnl.add(pathFld[index], gbc);
        pathBtn[index] = new JButton("Select...");
        pathBtn[index].setFont(ModifiableFontInfo.DIALOG_BUTTON.getFont());
        pathBtn[index].setName(String.valueOf(index));
        pathBtn[index].addActionListener(defaultListener);
        gbc.insets.right = 0;
        gbc.gridx++;
        innerPathPnl.add(pathBtn[index], gbc);
        gbc.insets.left = 0;
        gbc.weightx = 1.0;
        gbc.gridx++;
        innerPathPnl.add(new JLabel(""), gbc);
        gbc.insets.left = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
        gbc.insets.right = ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing() / 2;
        gbc.weightx = 0.0;
        gbc.gridx = 0;
        gbc.gridy++;
        index++;
    }
    // Set the scroll bar scroll increment
    pathScrollPane.getVerticalScrollBar().setUnitIncrement(pathFld[0].getPreferredSize().height / 2 + ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing());
    // Calculate the maximum required height of the panel containing the path labels and fields
    // (= # of rows * row height)
    maxScrollPaneHeight = Math.max(maxScrollPaneHeight, 10 * pathScrollPane.getPreferredSize().height / pathFld.length);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) JLabel(javax.swing.JLabel) ModifiablePathInfo(CCDD.CcddConstants.ModifiablePathInfo) JTextField(javax.swing.JTextField) BorderLayout(java.awt.BorderLayout) ActionListener(java.awt.event.ActionListener) Border(javax.swing.border.Border) BevelBorder(javax.swing.border.BevelBorder)

Example 14 with FileEnvVar

use of CCDD.CcddClassesComponent.FileEnvVar in project CCDD by nasa.

the class CcddScriptStorageDialog method initialize.

/**
 ********************************************************************************************
 * Create the script storage dialog
 ********************************************************************************************
 */
private void initialize() {
    // Create the dialog based on the supplied dialog type
    switch(dialogType) {
        case STORE:
            // Allow the user to select the script file path(s) + name(s)
            scriptFile = new CcddDialogHandler().choosePathFile(ccddMain, ccddMain.getMainFrame(), null, "script", scriptHandler.getExtensions(), true, "Select Script(s) to Store", ccddMain.getProgPrefs().get(ModifiablePathInfo.SCRIPT_PATH.getPreferenceKey(), null), DialogOption.STORE_OPTION);
            // Check if the Cancel button wasn't selected
            if (scriptFile != null) {
                // Check that a file is selected
                if (scriptFile[0] != null && scriptFile[0].isFile()) {
                    // Remove the script file name and store the script file path in the
                    // program preferences backing store
                    CcddFileIOHandler.storePath(ccddMain, scriptFile[0].getAbsolutePathWithEnvVars(), true, ModifiablePathInfo.SCRIPT_PATH);
                    // Step through each selected script
                    for (FileEnvVar file : scriptFile) {
                        // Store the script in the database
                        fileIOHandler.storeScriptInDatabase(file);
                    }
                } else // No script file is selected
                {
                    // Inform the user that a script file must be selected
                    new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Must select a script to store", "Store Script(s)", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                }
            }
            break;
        case RETRIEVE:
        case DELETE:
            // Set the initial layout manager characteristics
            GridBagConstraints gbc = new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.LINE_START, GridBagConstraints.BOTH, new Insets(ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_VERTICAL_SPACING.getSpacing(), ModifiableSpacingInfo.LABEL_HORIZONTAL_SPACING.getSpacing()), 0, 0);
            // Create the panel to contain the dialog components
            JPanel dialogPnl = new JPanel(new GridBagLayout());
            dialogPnl.setBorder(BorderFactory.createEmptyBorder());
            // Get the list of script files from the database
            String[] scripts = dbTable.queryScriptTables(ccddMain.getMainFrame());
            String[][] checkBoxData = new String[scripts.length][];
            int index = 0;
            // Step through each script file
            for (String script : scripts) {
                // Separate and store the database name and description
                checkBoxData[index] = script.split(",", 2);
                index++;
            }
            // which to choose
            if (addCheckBoxes(null, checkBoxData, null, "Select script(s)", dialogPnl)) {
                // Check if more than one data field name check box exists
                if (getCheckBoxes().length > 2) {
                    // Create a Select All check box
                    final JCheckBox selectAllCb = new JCheckBox("Select all scripts", false);
                    selectAllCb.setFont(ModifiableFontInfo.LABEL_BOLD.getFont());
                    selectAllCb.setBorder(BorderFactory.createEmptyBorder());
                    // Create a listener for changes to the Select All check box selection
                    // status
                    selectAllCb.addActionListener(new ActionListener() {

                        /**
                         ********************************************************************
                         * Handle a change to the Select All check box selection status
                         ********************************************************************
                         */
                        @Override
                        public void actionPerformed(ActionEvent ae) {
                            // Step through each data field name check box
                            for (JCheckBox scriptCb : getCheckBoxes()) {
                                // Set the check box selection status to match the Select All
                                // check box selection status
                                scriptCb.setSelected(selectAllCb.isSelected());
                            }
                        }
                    });
                    // Add the Select All checkbox to the dialog panel
                    gbc.gridx = 0;
                    gbc.gridy++;
                    gbc.insets.bottom = 0;
                    dialogPnl.add(selectAllCb, gbc);
                }
                // Check if one or more scripts is to be retrieved
                if (dialogType == ScriptIOType.RETRIEVE) {
                    // Add the script path selection components to the dialog
                    gbc.gridy++;
                    gbc.insets.bottom = 0;
                    dialogPnl.add(createPathSelectionPanel(), gbc);
                    // Display the script retrieval dialog
                    if (showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, "Retrieve Script(s)", DialogOption.RETRIEVE_OPTION, true) == OK_BUTTON) {
                        // Check if no script file path is selected via the selection button
                        if (scriptFile == null) {
                            // Get a file reference using the last accessed file path
                            scriptFile = new FileEnvVar[] { new FileEnvVar(ModifiablePathInfo.SCRIPT_PATH.getPath()) };
                        } else // A script file path is selected
                        {
                            // Store the script file path in the program preferences backing
                            // store
                            CcddFileIOHandler.storePath(ccddMain, scriptFile[0].getAbsolutePathWithEnvVars(), false, ModifiablePathInfo.SCRIPT_PATH);
                        }
                        // Get an array containing the selected script names
                        String[] selectedScripts = getCheckBoxSelected();
                        // Step through each selected script file
                        for (String script : selectedScripts) {
                            // Retrieve the selected scripts from the database and save them to
                            // the selected folder
                            fileIOHandler.retrieveScriptFromDatabase(script, new File(scriptFile[0].getAbsolutePath() + File.separator + script));
                        }
                    }
                } else // One or more scripts is to be deleted
                {
                    // Display the database deletion dialog
                    if (showOptionsDialog(ccddMain.getMainFrame(), dialogPnl, "Delete Script(s)", DialogOption.DELETE_OPTION, true) == OK_BUTTON) {
                        // Get the array of selected scripts
                        String[] selectedScripts = getCheckBoxSelected();
                        // Step through each script selected
                        for (index = 0; index < selectedScripts.length; index++) {
                            // Prepend the database script file identifier to the script name
                            selectedScripts[index] = InternalTable.SCRIPT.getTableName(selectedScripts[index]);
                        }
                        // Delete the selected scripts
                        dbTable.deleteTableInBackground(selectedScripts, null, ccddMain.getMainFrame());
                    }
                }
            } else // No scripts are stored in the database
            {
                // Inform the user that the project database contains no script to
                // retrieve/delete
                new CcddDialogHandler().showMessageDialog(ccddMain.getMainFrame(), "<html><b>Project '</b>" + dbControl.getDatabaseName() + "<b>' has no scripts", (dialogType == ScriptIOType.RETRIEVE ? "Retrieve" : "Delete") + " Script(s)", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
            }
            break;
    }
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) File(java.io.File)

Example 15 with FileEnvVar

use of CCDD.CcddClassesComponent.FileEnvVar in project CCDD by nasa.

the class CcddTableManagerDialog method verifySelection.

/**
 ********************************************************************************************
 * Verify that the dialog content is valid
 *
 * @return true if the input values are valid
 ********************************************************************************************
 */
@Override
protected boolean verifySelection() {
    // Assume the dialog input is valid
    boolean isValid = true;
    try {
        // Verify the dialog content based on the supplied dialog type
        switch(dialogType) {
            case NEW:
                // Remove any excess white space
                String names = nameFld.getText().trim();
                descriptionFld.setText(descriptionFld.getText().trim());
                // Store the cleaned table name
                nameFld.setText(names);
                // Check if a table type is selected
                if (getRadioButtonSelected() == null) {
                    // Inform the user that a table type must be selected
                    throw new CCDDException("Table type must be selected");
                }
                // Create a list to hold the new names already checked
                List<String> newNames = new ArrayList<String>();
                // Break the string of names into separate strings
                tableNames = names.split(",");
                // Step through each table name
                for (int index = 0; index < tableNames.length; index++) {
                    // Remove leading and trailing white space characters
                    String tableName = tableNames[index].trim();
                    // Force to lower case to remove case sensitivity
                    if (newNames.contains(tableName.toLowerCase())) {
                        // Inform the user that a table name is a duplicate
                        throw new CCDDException("Table name '" + tableName + "' is a duplicate");
                    }
                    // Check if the name is valid
                    verifyTableName(tableName);
                    // Add the new table name to the comparison list
                    newNames.add(tableName.toLowerCase());
                    // Store the cleaned table name into the array
                    tableNames[index] = tableName;
                }
                break;
            case RENAME:
            case COPY:
                // Remove any excess white space
                String tableName = nameFld.getText().trim();
                descriptionFld.setText(descriptionFld.getText().trim());
                // Store the cleaned table name
                nameFld.setText(tableName);
                // Check if the name is valid
                verifyTableName(tableName);
                break;
            case EDIT:
            case DELETE:
                // Check if no table has been selected
                if (tableTree.getSelectedTablesWithChildren().size() == 0) {
                    // Inform the user that no item has been selected
                    throw new CCDDException("Must select a table from the tree");
                }
                break;
            case IMPORT:
                // Remove any leading or trailing white space characters from the file
                // path/name
                getFileNameField().setText(getFileNameField().getText().trim());
                // Check if the name field is empty or contains no file name in the path
                if (getFileNameField().getText().isEmpty() || getFileNameField().getText().matches(".*\\" + File.separator + "\\.*?$")) {
                    // Inform the user that the import file is missing
                    new CcddDialogHandler().showMessageDialog(CcddTableManagerDialog.this, "<html><b>Must select an import file name", "Missing/Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
                    // Set the flag to indicate the dialog input is invalid
                    isValid = false;
                }
                break;
            case EXPORT_CSV:
            case EXPORT_EDS:
            case EXPORT_JSON:
            case EXPORT_XTCE:
                // Remove any leading or trailing white space characters from the file
                // path/name
                pathFld.setText(pathFld.getText().trim());
                // been selected
                if (callingEditorDialog == null && tableTree.getSelectedTablesWithChildren().size() == 0) {
                    // Inform the user that no table has been selected
                    throw new CCDDException("Must select a table from the tree");
                }
                // Check if the table(s) are to be stored in a single file
                if (singleFileRBtn.isSelected()) {
                    // Check if the name field is empty or contains no file name in the path
                    if (pathFld.getText().isEmpty() || pathFld.getText().matches(".*\\" + File.separator + "\\.*?$")) {
                        // Inform the user that no file name has been selected
                        throw new CCDDException("Must select an export file name");
                    }
                    // Create a file reference from the file path/name
                    FileEnvVar file = new FileEnvVar(pathFld.getText());
                    // Check if the selection is a directory instead of a file name
                    if (file.isDirectory()) {
                        // selected
                        throw new CCDDException("Directory name cannot be selected as the file name");
                    } else // Check if the file already exists; if so, the name is valid
                    if (!file.exists()) {
                        try {
                            // Attempt to create the file; an exception is thrown if
                            // unsuccessful
                            file.createNewFile();
                            // The file was successfully created; delete it
                            file.delete();
                        } catch (Exception e) {
                            // file can't be created
                            throw new CCDDException("Invalid export file name");
                        }
                    }
                }
                // Check if exporting in XTCE XML format
                if (dialogType == ManagerDialogType.EXPORT_XTCE) {
                    // Remove any excess white space
                    versionFld.setText(versionFld.getText().trim());
                    validStatFld.setText(validStatFld.getText().trim());
                    class1Fld.setText(class1Fld.getText().trim());
                    class2Fld.setText(class2Fld.getText().trim());
                    class3Fld.setText(class3Fld.getText().trim());
                    // Check if any of the fields is blank
                    if (versionFld.getText().isEmpty() || validStatFld.getText().isEmpty() || class1Fld.getText().isEmpty() || class2Fld.getText().isEmpty() || class3Fld.getText().isEmpty()) {
                        // Inform the user that a required field is missing
                        throw new CCDDException("System data field name, version, " + "validation status, and/or " + "classification missing");
                    }
                }
                break;
        }
    } catch (CCDDException ce) {
        // Inform the user that the input value is invalid
        new CcddDialogHandler().showMessageDialog(CcddTableManagerDialog.this, "<html><b>" + ce.getMessage(), "Missing/Invalid Input", JOptionPane.WARNING_MESSAGE, DialogOption.OK_OPTION);
        // Set the flag to indicate the dialog input is invalid
        isValid = false;
    }
    return isValid;
}
Also used : CCDDException(CCDD.CcddClassesDataTable.CCDDException) ArrayList(java.util.ArrayList) FileEnvVar(CCDD.CcddClassesComponent.FileEnvVar) CCDDException(CCDD.CcddClassesDataTable.CCDDException)

Aggregations

FileEnvVar (CCDD.CcddClassesComponent.FileEnvVar)17 CCDDException (CCDD.CcddClassesDataTable.CCDDException)11 ArrayList (java.util.ArrayList)7 SimpleDateFormat (java.text.SimpleDateFormat)6 JPanel (javax.swing.JPanel)5 FileNameExtensionFilter (javax.swing.filechooser.FileNameExtensionFilter)5 GridBagConstraints (java.awt.GridBagConstraints)4 GridBagLayout (java.awt.GridBagLayout)4 Insets (java.awt.Insets)4 IOException (java.io.IOException)4 ResultSet (java.sql.ResultSet)4 SQLException (java.sql.SQLException)4 TypeDefinition (CCDD.CcddTableTypeHandler.TypeDefinition)3 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JCheckBox (javax.swing.JCheckBox)3 TableDefinition (CCDD.CcddClassesDataTable.TableDefinition)2 File (java.io.File)2 Border (javax.swing.border.Border)2 BackgroundCommand (CCDD.CcddBackgroundCommand.BackgroundCommand)1