Search in sources :

Example 1 with Record

use of com.ibm.as400.access.Record in project IBMiProgTool by vzupka.

the class Copy_PC_IBMi method copyFromPcDirectory.

/**
 * Copying a PC directory to IFS directory or to Library/Source File.
 *
 * @param sourcePathString
 * @param targetPathString
 * @param sourcePathStringPrefix
 */
protected void copyFromPcDirectory(String sourcePathString, String targetPathString, String sourcePathStringPrefix) {
    // Get object and member names (libraryName, fileName, memberName
    extractNamesFromIfsPath(targetPathString);
    if (!sourcePathString.contains(pcFileSep + ".")) {
        IFSFile targetPath = new IFSFile(remoteServer, targetPathString + "/" + sourcePathString.substring(sourcePathStringPrefix.length()));
        // --------------------------------
        if (!targetPathString.startsWith("/QSYS.LIB")) {
            // Create the first shadow IFS directory
            try {
                if (!targetPath.exists()) {
                    // Create new directory in target IFS directory with PC file ending name
                    targetPath.mkdir();
                    // Add message text to the message table and show it
                    row = "Info: Directory  " + sourcePathString + "  was created in IFS directory  " + targetPathString + ".";
                    mainWindow.msgVector.add(row);
                }
            } catch (Exception exc) {
                exc.printStackTrace();
                row = exc.toString();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
                return;
            }
            // Create shadow directories in the first shadow IFS directory created above
            msgText = walkPcDirectory_CreateNestedIfsDirectories(remoteServer, sourcePathString, targetPath);
            // Copy PC files to appropriate IFS shadow directories
            msgText = copyPcFilesToIfsDirectories(sourcePathString, targetPath, sourcePathStringPrefix);
            // Construct a message in the message table and show it
            if (msgText.isEmpty()) {
                row = "Comp: PC directory  " + sourcePathString + "  was copied to IFS directory  " + targetPathString + ".";
            } else {
                row = "Comp: PC directory  " + sourcePathString + "  was NOT completely copied to IFS directory  " + targetPathString + ".";
            }
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
        }
        // ------------------
        if (targetPathString.startsWith("/QSYS.LIB")) {
            if (ibmCcsid.equals("*DEFAULT")) {
                ibmCcsid = "500";
            }
            // Create new source physical file in the library and call copyToSourceFile() method
            if (targetPathString.endsWith(".LIB")) {
                // Extract individual names (libraryName, fileName, memberName) from the AS400 IFS path
                extractNamesFromIfsPath(targetPathString);
                // Extract a new file name from the last component of the PC path string.
                // The file name extracted by the method before was null!
                fileName = sourcePathString.substring(sourcePathString.lastIndexOf(pcFileSep) + 1);
                // Create new source physical file
                String sourceRecordLength = (String) properties.get("SOURCE_RECORD_LENGTH");
                // The property contains all digits. It was made certain when the user entered the value.
                int sourceRecordLengthInt = Integer.parseInt(sourceRecordLength);
                // Source record must contain 12 byte prefix to data line: sequence number (6) and date (6)
                sourceRecordLengthInt += 12;
                // Build command CRTSRCPF to create a source physical file with certain CCSID in the library
                String commandText = "CRTSRCPF FILE(" + libraryName + "/" + fileName + ") " + "RCDLEN(" + sourceRecordLengthInt + ") CCSID(" + ibmCcsid + ")";
                // Enable calling CL commands
                CommandCall cmdCall = new CommandCall(remoteServer);
                try {
                    // Run the command
                    cmdCall.run(commandText);
                    // Get messages from the command if any
                    AS400Message[] as400MessageList = cmdCall.getMessageList();
                    // Send all messages from the command. After ESCAPE message - return.
                    for (AS400Message as400Message : as400MessageList) {
                        if (as400Message.getType() == AS400Message.ESCAPE) {
                            row = "Error: Create source physical file  " + libraryName + "/" + fileName + " using CRTSRCPF command  -  " + as400Message.getID() + " " + as400Message.getText();
                            mainWindow.msgVector.add(row);
                            mainWindow.showMessages();
                            return;
                        } else {
                            row = "Info: Create source physical file  " + libraryName + "/" + fileName + " using CRTSRCPF command  -  " + as400Message.getID() + " " + as400Message.getText();
                            mainWindow.msgVector.add(row);
                            mainWindow.showMessages();
                        }
                    }
                } catch (Exception exc) {
                    exc.printStackTrace();
                    row = "Error: Copying PC directory  " + sourcePathString + "  to source physical File  " + libraryName + "/" + fileName + "  -  " + exc.toString();
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages();
                    // Must return! Could be fatal error (e. g. lock of the source file)!
                    return;
                }
                // Copy members to the new source physical file in a library
                msgText = copyToSourceFile(sourcePathString, targetPathString + "/" + fileName + ".FILE");
                if (msgText.isEmpty()) {
                    row = "Comp: PC directory  " + sourcePathString + "  was copied to source physical file  " + libraryName + "/" + fileName + ".";
                } else {
                    row = "Comp: PC directory  " + sourcePathString + "  was NOT completely copied to source physical file  " + libraryName + "/" + fileName + ".";
                }
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
            } else // ---------------------------------------------------------
            if (targetPathString.endsWith(".FILE")) {
                // Copy single PC file to source file to existing member or as a new member
                msgText = copyToSourceFile(sourcePathString, targetPathString);
                if (msgText.isEmpty()) {
                    row = "Comp: PC directory  " + sourcePathString + "  was copied to source physical file  " + libraryName + "/" + fileName + ".";
                } else {
                    row = "Comp: PC directory  " + sourcePathString + "  was NOT completely copied to source physical file  " + libraryName + "/" + fileName + ".";
                }
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
            } else // ----------------------------------------
            if (targetPathString.endsWith(".MBR")) {
                row = "Error: PC directory  " + sourcePathString + "  cannot be copied to a source physical file member  " + libraryName + "/" + fileName + "(" + memberName + ").";
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
            }
        }
    }
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) AS400Message(com.ibm.as400.access.AS400Message) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IFSFile(com.ibm.as400.access.IFSFile)

Example 2 with Record

use of com.ibm.as400.access.Record in project IBMiProgTool by vzupka.

the class Copy_PC_IBMi method copyToSourceMember.

/**
 * Copy PC text file to the IBM i source member.
 *
 * @param sourcePathString
 * @param targetPathString
 * @param fromDirectory
 * @return
 */
protected String copyToSourceMember(String sourcePathString, String targetPathString, boolean fromDirectory) {
    if (ibmCcsid.equals("*DEFAULT")) {
        ibmCcsid = "500";
        ibmCcsidInt = 500;
    }
    // Extract individual names (libraryName, fileName, memberName) from the AS400 IFS path
    extractNamesFromIfsPath(targetPathString);
    if (sourcePathString.endsWith(pcFileSep)) {
        sourcePathString = sourcePathString.substring(0, sourcePathString.lastIndexOf(pcFileSep));
    }
    // Get source type from the PC file name
    String sourceType;
    if (sourcePathString.lastIndexOf(".") > 0) {
        // If file name has postfix with a dot, the posfix will be the source type
        sourceType = sourcePathString.substring(sourcePathString.lastIndexOf(".") + 1);
    } else {
        // If file name does not have a postfix (there is no dot), the source type will be MBR
        sourceType = "MBR";
    }
    // Path to input PC text file
    Path inTextFile = Paths.get(sourcePathString);
    // Path to the output source member
    String outMemberPathString = "/QSYS.LIB/" + libraryName + ".LIB/" + fileName + ".FILE" + "/" + memberName + ".MBR";
    IFSFile ifsMbr = new IFSFile(remoteServer, outMemberPathString);
    String clrPfmCommand;
    String chgPfmCommand;
    // Enable calling CL commands
    CommandCall cmdCall = new CommandCall(remoteServer);
    msgText = "";
    try {
        // Open PC input file regarded as a text file.
        if (pcCharset.equals("*DEFAULT")) {
            // Decode input using its encoding. Ignore PC charset parameter.
            inFile = Files.newBufferedReader(inTextFile);
        } else {
            // Decode input using PC charset parameter.
            inFile = Files.newBufferedReader(inTextFile, Charset.forName(pcCharset));
        }
        try {
            // Read the first text line
            textLine = inFile.readLine();
        // If an error is found in the first line of the file,
        // processing is broken, the error is caught (see catch blocks), a message is reported,
        // and no member is created.
        } catch (Exception exc) {
            exc.printStackTrace();
            row = "Error: Data of the PC file  " + sourcePathString + "  cannot be copied to the source physical file  " + libraryName + "/" + fileName + "  -  " + exc.toString();
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            msgText = "ERROR";
            return msgText;
        }
        // -----------------------------------
        if (ifsMbr.exists() && !properties.getProperty("OVERWRITE_FILE").equals("Y")) {
            row = "Info: PC file  " + sourcePathString + "  cannot be copied to the existing source physical member  " + libraryName + "/" + fileName + "(" + memberName + "). Overwriting files is not allowed.";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "ERROR";
        }
        // SEQUENCE NUMBER and DATE information fields in the first 6 + 6 positions.
        try {
            // Non-empty member can be checked for information fields if the line is longer than 12
            if (textLine != null && textLine.length() > 12) {
                int seqNbr = Integer.parseInt(textLine.substring(0, 6));
                int date = Integer.parseInt(textLine.substring(6, 12));
                seqAndDatePresent = true;
            } else {
                // Otherwise the line cannot have information fields
                seqAndDatePresent = false;
            }
        } catch (NumberFormatException nfe) {
            seqAndDatePresent = false;
        }
        if (seqAndDatePresent) {
            // Input records contain sequence and data fields
            // ----------------------------------------------
            // Copying is done directly using a sequential file preserving sequence and data field values.
            // Clear physical file member
            clrPfmCommand = "CLRPFM FILE(" + libraryName + "/" + fileName + ") MBR(" + memberName + ")";
            cmdCall.run(clrPfmCommand);
            // Obtain output database file record description
            AS400FileRecordDescription outRecDesc = new AS400FileRecordDescription(remoteServer, outMemberPathString);
            // Retrieve record format from the record description
            RecordFormat[] format = outRecDesc.retrieveRecordFormat();
            // Obtain output record object
            Record outRecord = new Record(format[0]);
            // 
            // Note: Now create the member if no error was found in the first text line.
            // -----
            // 
            // Create the member (SequentialFile object)
            outSeqFile = new SequentialFile(remoteServer, outMemberPathString);
            // Set the record format (the only one)
            outSeqFile.setRecordFormat(format[0]);
            try {
                // Open the member
                outSeqFile.open();
            } catch (com.ibm.as400.access.AS400Exception as400exc) {
                // as400exc.printStackTrace();
                // Add new member if open could not be performed (when the member does not exist)
                // (the second parameter is a text description)
                // The new member inherits the CCSID from its parent Source physical file
                outSeqFile.addPhysicalFileMember(memberName, "Source member " + memberName);
                // Change member to set its Source Type
                chgPfmCommand = "CHGPFM FILE(" + libraryName + "/" + fileName + ") MBR(" + memberName + ") SRCTYPE(" + sourceType + ")";
                // Perform the CL command
                cmdCall.run(chgPfmCommand);
                // Open the new member
                outSeqFile.open();
            }
            // Process all lines
            while (textLine != null) {
                // Get lengths of three fields of the source record
                int lenSEQ = format[0].getFieldDescription("SRCSEQ").getLength();
                int lenDAT = format[0].getFieldDescription("SRCDAT").getLength();
                // Set the three field values from the input text line according to their lengths
                outRecord.setField("SRCSEQ", new BigDecimal(new BigInteger(textLine.substring(0, lenSEQ)), 2));
                outRecord.setField("SRCDAT", new BigDecimal(textLine.substring(lenSEQ, lenSEQ + lenDAT)));
                outRecord.setField("SRCDTA", textLine.substring(lenSEQ + lenDAT));
                try {
                    // Write source record
                    outSeqFile.write(outRecord);
                    // Read next text line
                    textLine = inFile.readLine();
                } catch (Exception exc) {
                    exc.printStackTrace();
                    row = "Error: 1 Data of the PC file  " + sourcePathString + "  cannot be copied to the source physical file  " + libraryName + "/" + fileName + "  -  " + exc.toString();
                    mainWindow.msgVector.add(row);
                    mainWindow.showMessages();
                    msgText = "ERROR";
                    break;
                }
            }
            // Close files
            inFile.close();
            outSeqFile.close();
        } else {
            // Input records DO NOT contain sequence and data fields
            // -----------------------------------------------------
            // Copying is done indirectly using a temporary IFS file in the /home/userName directory.
            // First create an IFS '/home/userName directory if it does not exist
            String home_userName = "/home/" + userName;
            IFSFile ifsDir = new IFSFile(remoteServer, home_userName);
            // Create new directory
            ifsDir.mkdir();
            // String for command CHGATR to set CCSID attribute of the new directory
            String command_CHGATR = "CHGATR OBJ('" + home_userName + ") ATR(*CCSID) VALUE(" + ibmCcsid + ") SUBTREE(*ALL)";
            // Perform the command
            cmdCall.run(command_CHGATR);
            // Create hidden temporary file (with leading dot) in the directory
            String tmp_File = home_userName + "/.tmp" + Timestamp.valueOf(LocalDateTime.now()).toString();
            IFSFile ifsTmpFile = new IFSFile(remoteServer, tmp_File);
            ifsTmpFile.createNewFile();
            // Copy PC file to temporary IFS file
            copyFromPcFile(sourcePathString, tmp_File, notFromWalk);
            // Copy data from temporary IFS file to the member. If the member does not exist it is created.
            String commandCpyFrmStmfString = "CPYFRMSTMF FROMSTMF('" + tmp_File + "') TOMBR('" + targetPathString + "') MBROPT(*REPLACE) CVTDTA(*AUTO) STMFCCSID(*STMF) DBFCCSID(*FILE)";
            // Perform the command
            cmdCall.run(commandCpyFrmStmfString);
            // Delete the temporary file
            ifsTmpFile.delete();
        }
        row = "Info: PC file  " + sourcePathString + "  was copied to source physical file member  " + libraryName + "/" + fileName + "(" + memberName + "). Convert " + pcCharset + " -> " + ibmCcsid + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
        if (!msgText.isEmpty()) {
            return "ERROR";
        }
        if (msgText.isEmpty() && !fromDirectory) {
            row = "Comp: PC file  " + sourcePathString + "  was copied to source physical file member  " + libraryName + "/" + fileName + "(" + memberName + "). Convert " + pcCharset + " -> " + ibmCcsid + ".";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "";
        }
        if (!msgText.isEmpty() && !fromDirectory) {
            row = "Comp: PC file  " + sourcePathString + "  was NOT completely copied to source physical file member  " + libraryName + "/" + fileName + "(" + memberName + "). Convert " + pcCharset + " -> " + ibmCcsid + ".";
            mainWindow.msgVector.add(row);
            mainWindow.showMessages();
            return "ERROR";
        }
    } catch (Exception exc) {
        try {
            inFile.close();
            outSeqFile.close();
        } catch (Exception exce) {
            exce.printStackTrace();
        }
        exc.printStackTrace();
        row = "Error: 3 PC file  " + sourcePathString + "  cannot be copied to the source physical file  " + libraryName + "/" + fileName + "  -  " + exc.toString();
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
        // Must not continue in order not to lock an object
        return "ERROR";
    }
    return "";
}
Also used : Path(java.nio.file.Path) CommandCall(com.ibm.as400.access.CommandCall) SequentialFile(com.ibm.as400.access.SequentialFile) RecordFormat(com.ibm.as400.access.RecordFormat) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) BigDecimal(java.math.BigDecimal) AS400FileRecordDescription(com.ibm.as400.access.AS400FileRecordDescription) BigInteger(java.math.BigInteger) Record(com.ibm.as400.access.Record) IFSFile(com.ibm.as400.access.IFSFile)

Example 3 with Record

use of com.ibm.as400.access.Record in project IBMiProgTool by vzupka.

the class CreateAndDeleteInIBMi method createSourcePhysicalFile.

/**
 * Create Source Physical File.
 */
protected void createSourcePhysicalFile() {
    // Get library name from the IFS path string
    extractNamesFromIfsPath(mainWindow.rightPathString);
    // "true" stands for changing result to upper case
    String sourceFileName = new GetTextFromDialog("CREATE NEW SOURCE PHYSICAL FILE").getTextFromDialog("Library", "Source physical file name", libraryName, "", true, currentX, currentY);
    if (sourceFileName == null) {
        return;
    }
    if (sourceFileName.isEmpty()) {
        sourceFileName = "QRPGLESRC";
    }
    // Get and adjust source record length
    sourceRecordLength = (String) properties.get("SOURCE_RECORD_LENGTH");
    // The property contains all digits. It was made certain when the user entered the value.
    int sourceRecordLengthInt = Integer.parseInt(sourceRecordLength);
    // Source record must contain 12 byte prefix to data line: sequence number (6) and date (6)
    sourceRecordLengthInt += 12;
    // Build command CRTSRCPF to create a source physical file with certain CCSID in the library
    String commandText = "CRTSRCPF FILE(" + libraryName + "/" + sourceFileName + ") " + "RCDLEN(" + sourceRecordLengthInt + ") CCSID(" + ibmCcsid + ")";
    // Enable calling CL commands
    CommandCall command = new CommandCall(remoteServer);
    try {
        // Run the command
        command.run(commandText);
        // Get messages from the command if any
        AS400Message[] as400MessageList = command.getMessageList();
        String msgType;
        // Send all messages from the command. After ESCAPE message - return.
        for (AS400Message as400Message : as400MessageList) {
            if (as400Message.getType() == AS400Message.ESCAPE) {
                msgType = "Error";
                row = msgType + ": message from the CRTSRCPF command is " + as400Message.getID() + " " + as400Message.getText();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
                return;
            } else {
                msgType = "Info";
                row = msgType + ": message from the CRTSRCPF command is " + as400Message.getID() + " " + as400Message.getText();
                mainWindow.msgVector.add(row);
                mainWindow.showMessages();
            }
        }
    } catch (Exception exc) {
        exc.printStackTrace();
        row = "Error: Creating source physical file  " + ifsFile.toString() + " - " + exc.toString() + ".";
        mainWindow.msgVector.add(row);
        mainWindow.showMessages();
        return;
    }
    row = "Comp: Source physical file  " + sourceFileName + "  was created in  " + libraryName + ".";
    mainWindow.msgVector.add(row);
    mainWindow.showMessages();
}
Also used : CommandCall(com.ibm.as400.access.CommandCall) AS400Message(com.ibm.as400.access.AS400Message)

Example 4 with Record

use of com.ibm.as400.access.Record in project IBMiProgTool by vzupka.

the class MainWindow method createWindow.

/**
 * Create window containing trees with initial files in upper part; Left tree
 * shows local file system; Right tree shows IBM i file system (IFS).
 */
public void createWindow() {
    cont = getContentPane();
    globalPanel = new JPanel();
    globalPanelLayout = new GroupLayout(globalPanel);
    menuBar = new JMenuBar();
    helpMenu = new JMenu("Help");
    helpMenuItemEN = new JMenuItem("Help English");
    helpMenuItemCZ = new JMenuItem("Nápověda česky");
    helpMenuItemRPGIII = new JMenuItem("RPG III forms");
    helpMenuItemRPGIV = new JMenuItem("RPG IV forms");
    helpMenuItemCOBOL = new JMenuItem("COBOL form");
    helpMenuItemDDS = new JMenuItem("DDS forms");
    helpMenu.add(helpMenuItemEN);
    helpMenu.add(helpMenuItemCZ);
    helpMenu.add(helpMenuItemRPGIII);
    helpMenu.add(helpMenuItemRPGIV);
    helpMenu.add(helpMenuItemCOBOL);
    helpMenu.add(helpMenuItemDDS);
    menuBar.add(helpMenu);
    // In macOS on the main system menu bar above, in Windows on the window menu bar
    setJMenuBar(menuBar);
    panelTop = new JPanel();
    panelTopLayout = new GroupLayout(panelTop);
    panelTop.setLayout(panelTopLayout);
    panelPathLeft = new JPanel();
    panelPathLeft.setLayout(new BoxLayout(panelPathLeft, BoxLayout.LINE_AXIS));
    scrollPaneLeft = new JScrollPane();
    scrollPaneLeft.setBorder(BorderFactory.createEmptyBorder());
    panelPathRight = new JPanel();
    panelPathRight.setLayout(new BoxLayout(panelPathRight, BoxLayout.LINE_AXIS));
    scrollPaneRight = new JScrollPane();
    scrollPaneRight.setBorder(BorderFactory.createEmptyBorder());
    // Windows: Disks combo box is included in order to choose proper root
    // directory (A:\, C:\, ...)
    Component diskLabelWin;
    Component disksComboBoxWin;
    if (operatingSystem.equals(WINDOWS)) {
        diskLabelWin = disksLabel;
        disksComboBoxWin = disksComboBox;
    } else {
        // 
        // Unix (Mac): Empty component instead of combo box
        diskLabelWin = new JLabel("");
        disksComboBoxWin = new JLabel("");
    }
    disksComboBox.setToolTipText("List of root directories.");
    // Lay out components in panelTop
    panelTopLayout.setAutoCreateGaps(false);
    panelTopLayout.setAutoCreateContainerGaps(false);
    panelTopLayout.setHorizontalGroup(panelTopLayout.createParallelGroup(Alignment.LEADING).addGroup(panelTopLayout.createSequentialGroup().addComponent(userNameLabel).addComponent(userNameTextField).addComponent(hostLabel).addComponent(hostTextField).addComponent(connectReconnectButton).addGap(5).addComponent(libraryPatternLabel).addComponent(libraryPatternTextField).addGap(5).addComponent(filePatternLabel).addComponent(filePatternTextField).addGap(5).addComponent(memberPatternLabel).addComponent(memberPatternTextField).addGap(5).addComponent(sourceTypeLabel).addComponent(sourceTypeComboBox)).addGroup(panelTopLayout.createSequentialGroup().addComponent(pcCharsetLabel).addComponent(pcCharComboBox).addComponent(ibmCcsidLabel).addComponent(ibmCcsidComboBox).addComponent(sourceRecordLengthLabel).addComponent(sourceRecordLengthTextField).addComponent(sourceRecordPrefixLabel).addComponent(sourceRecordPrefixCheckBox).addComponent(overwriteOutputFileLabel).addComponent(overwriteOutputFileCheckBox).addComponent(diskLabelWin).addComponent(disksComboBoxWin)));
    panelTopLayout.setVerticalGroup(panelTopLayout.createSequentialGroup().addGroup(panelTopLayout.createParallelGroup(Alignment.CENTER).addComponent(userNameLabel).addComponent(userNameTextField).addComponent(hostLabel).addComponent(hostTextField).addComponent(connectReconnectButton).addGap(5).addComponent(libraryPatternLabel).addComponent(libraryPatternTextField).addGap(5).addComponent(filePatternLabel).addComponent(filePatternTextField).addGap(5).addComponent(memberPatternLabel).addComponent(memberPatternTextField).addGap(5).addComponent(sourceTypeLabel).addComponent(sourceTypeComboBox)).addGroup(panelTopLayout.createParallelGroup(Alignment.CENTER).addComponent(pcCharsetLabel).addComponent(pcCharComboBox).addComponent(ibmCcsidLabel).addComponent(ibmCcsidComboBox).addComponent(sourceRecordLengthLabel).addComponent(sourceRecordLengthTextField).addComponent(sourceRecordPrefixLabel).addComponent(sourceRecordPrefixCheckBox).addComponent(overwriteOutputFileLabel).addComponent(overwriteOutputFileCheckBox).addComponent(diskLabelWin).addComponent(disksComboBoxWin)));
    panelTop.setLayout(panelTopLayout);
    panelPathLeft.add(leftPathLabel);
    leftPathComboBox.setEditable(true);
    panelPathLeft.add(leftPathComboBox);
    panelPathRight.add(rightPathLabel);
    rightPathComboBox.setEditable(true);
    panelPathRight.add(rightPathComboBox);
    panelLeft = new JPanel();
    panelLeft.setLayout(new BorderLayout());
    panelLeft.add(panelPathLeft, BorderLayout.NORTH);
    panelLeft.add(scrollPaneLeft, BorderLayout.CENTER);
    panelRight = new JPanel();
    panelRight.setLayout(new BorderLayout());
    panelRight.add(panelPathRight, BorderLayout.NORTH);
    panelRight.add(scrollPaneRight, BorderLayout.CENTER);
    // Split pane inner - divided by horizontal divider
    splitPaneInner = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    splitPaneInner.setLeftComponent(panelLeft);
    splitPaneInner.setRightComponent(panelRight);
    splitPaneInner.setDividerSize(6);
    splitPaneInner.setBorder(BorderFactory.createEmptyBorder());
    // Scroll pane for message list
    scrollMessagePane.setBorder(BorderFactory.createEmptyBorder());
    // Split pane outer - divided by vertical divider
    splitPaneOuter = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    splitPaneOuter.setTopComponent(splitPaneInner);
    splitPaneOuter.setBottomComponent(scrollMessagePane);
    splitPaneOuter.setDividerSize(6);
    splitPaneOuter.setBorder(BorderFactory.createEmptyBorder());
    // This listener keeps the scroll pane at the LAST MESSAGE.
    messageScrollPaneAdjustmentListenerMax = new MessageScrollPaneAdjustmentListenerMax();
    // List of messages for placing into message scroll pane
    messageList = new JList<String>();
    // Decision what color the message will get
    messageList.setCellRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value.toString().startsWith("Comp")) {
                this.setForeground(DIM_BLUE);
            } else if (value.toString().startsWith("Err")) {
                this.setForeground(DIM_RED);
            } else if (value.toString().startsWith("Info")) {
                this.setForeground(Color.GRAY);
            } else if (value.toString().startsWith("Wait")) {
                this.setForeground(DIM_PINK);
            } else {
                this.setForeground(Color.BLACK);
            }
            return component;
        }
    });
    // Build messageTable and put it to scrollMessagePane and panelMessages
    buildMessageList();
    // Create left tree showing local file system
    // ----------------
    leftRoot = properties.getProperty("LEFT_PATH");
    // ----------------------------------------------
    // Create new left side
    // ----------------------------------------------
    // Create split panes containing the PC file tree on the left side of the window
    createNewLeftSide(leftRoot);
    // Lay out the window components using GroupLayout
    // -----------------------------
    globalPanelLayout.setAutoCreateGaps(false);
    globalPanelLayout.setAutoCreateContainerGaps(false);
    globalPanelLayout.setHorizontalGroup(globalPanelLayout.createSequentialGroup().addGroup(globalPanelLayout.createParallelGroup().addComponent(panelTop).addComponent(splitPaneOuter)));
    globalPanelLayout.setVerticalGroup(globalPanelLayout.createParallelGroup().addGroup(globalPanelLayout.createSequentialGroup().addComponent(panelTop).addComponent(splitPaneOuter)));
    // Create a global panel to wrap the layout
    globalPanel.setLayout(globalPanelLayout);
    // Set border to the global panel - before it is visible
    globalPanel.setBorder(BorderFactory.createLineBorder(globalPanel.getBackground(), borderWidth));
    // When the split pane is visible - can divide it by percentage
    // 50 %
    double splitPaneInnerDividerLoc = 0.50d;
    // Percentage to reveal the first message line height when the scroll pane is full
    double splitPaneOuterDividerLoc = 0.835d;
    splitPaneInner.setDividerLocation(splitPaneInnerDividerLoc);
    splitPaneOuter.setDividerLocation(splitPaneOuterDividerLoc);
    // Stabilize vertical divider always in the middle
    splitPaneInner.setResizeWeight(0.5);
    // Register WindowListener for storing X and Y coordinates to properties
    addWindowListener(new MainWindowAdapter());
    // Register HelpWindow menu item listener
    helpMenuItemEN.addActionListener(ae -> {
        String command = ae.getActionCommand();
        if (command.equals("Help English")) {
            if (Desktop.isDesktopSupported()) {
                String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "IBMiProgTool_doc_EN.pdf").toString();
                // Replace backslashes by forward slashes in Windows
                uri = uri.replace('\\', '/');
                uri = uri.replace(" ", "%20");
                try {
                    // Invoke the standard browser in the operating system
                    Desktop.getDesktop().browse(new URI("file://" + uri));
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
    });
    // Register HelpWindow menu item listener
    helpMenuItemCZ.addActionListener(ae -> {
        String command = ae.getActionCommand();
        if (command.equals("Nápověda česky")) {
            if (Desktop.isDesktopSupported()) {
                String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "IBMiProgTool_doc_CZ.pdf").toString();
                // Replace backslashes by forward slashes in Windows
                uri = uri.replace('\\', '/');
                uri = uri.replace(" ", "%20");
                try {
                    // Invoke the standard browser in the operating system
                    Desktop.getDesktop().browse(new URI("file://" + uri));
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
    });
    // Register HelpWindow menu item listener
    helpMenuItemRPGIII.addActionListener(ae -> {
        String command = ae.getActionCommand();
        if (command.equals("RPG III forms")) {
            if (Desktop.isDesktopSupported()) {
                String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "RPG_III_forms.pdf").toString();
                // Replace backslashes by forward slashes in Windows
                uri = uri.replace('\\', '/');
                try {
                    // Invoke the standard browser in the operating system
                    Desktop.getDesktop().browse(new URI("file://" + uri));
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
    });
    // Register HelpWindow menu item listener
    helpMenuItemRPGIV.addActionListener(ae -> {
        String command = ae.getActionCommand();
        if (command.equals("RPG IV forms")) {
            if (Desktop.isDesktopSupported()) {
                String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "RPG_IV_forms.pdf").toString();
                // Replace backslashes by forward slashes in Windows
                uri = uri.replace('\\', '/');
                uri = uri.replace(" ", "%20");
                try {
                    // Invoke the standard browser in the operating system
                    Desktop.getDesktop().browse(new URI("file://" + uri));
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
    });
    // Register HelpWindow menu item listener
    helpMenuItemCOBOL.addActionListener(ae -> {
        String command = ae.getActionCommand();
        if (command.equals("COBOL form")) {
            if (Desktop.isDesktopSupported()) {
                String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "COBOL_form.pdf").toString();
                // Replace backslashes by forward slashes in Windows
                uri = uri.replace('\\', '/');
                uri = uri.replace(" ", "%20");
                try {
                    // Invoke the standard browser in the operating system
                    Desktop.getDesktop().browse(new URI("file://" + uri));
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
    });
    // Register HelpWindow menu item listener
    helpMenuItemDDS.addActionListener(ae -> {
        String command = ae.getActionCommand();
        if (command.equals("DDS forms")) {
            if (Desktop.isDesktopSupported()) {
                String uri = Paths.get(System.getProperty("user.dir"), "helpfiles", "DDS_forms.pdf").toString();
                // Replace backslashes by forward slashes in Windows
                uri = uri.replace('\\', '/');
                uri = uri.replace(" ", "%20");
                try {
                    // Invoke the standard browser in the operating system
                    Desktop.getDesktop().browse(new URI("file://" + uri));
                } catch (Exception exc) {
                    exc.printStackTrace();
                }
            }
        }
    });
    // Set left path string as selected in the left combo box
    leftPathComboBox.setSelectedItem(leftPathString);
    // Set also right path string in the right combo box
    rightPathComboBox.setSelectedItem(rightPathString);
    // 
    // User name text field action
    // ---------------------------
    userNameTextField.addActionListener(ae -> {
        userNameTextField.setText(userNameTextField.getText().toUpperCase());
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            properties.setProperty("USERNAME", userNameTextField.getText());
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
            refreshWindow();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Host text field action
    // ----------------------
    hostTextField.addActionListener(ae -> {
        hostTextField.setText(hostTextField.getText());
        // Connect or reconnect the server
        connectReconnectRefresh();
    });
    // 
    // Source Type combo box item listener
    // ---------------------
    sourceTypeComboBox.addItemListener(il -> {
        // JComboBox<String> source = new
        // JComboBox<String>((String[])il.getSource());
        JComboBox<String[]> source = (JComboBox) il.getSource();
        sourceType = (String) source.getSelectedItem();
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            properties.setProperty("SOURCE_TYPE", sourceType);
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Library pattern text field action
    // -------------------------
    libraryPatternTextField.addActionListener(ae -> {
        libraryPatternTextField.setText(libraryPatternTextField.getText().toUpperCase());
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            properties.setProperty("LIBRARY_PATTERN", libraryPatternTextField.getText());
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
            connectReconnectRefresh();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Source file pattern text field action
    // ------------------------------------
    filePatternTextField.addActionListener(ae -> {
        filePatternTextField.setText(filePatternTextField.getText().toUpperCase());
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            properties.setProperty("FILE_PATTERN", filePatternTextField.getText());
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
            connectReconnectRefresh();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Member pattern text field action
    // -------------------------------
    memberPatternTextField.addActionListener(ae -> {
        memberPatternTextField.setText(memberPatternTextField.getText().toUpperCase());
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            properties.setProperty("MEMBER_PATTERN", memberPatternTextField.getText());
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
            connectReconnectRefresh();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Source record length text field action
    // --------------------------------------
    sourceRecordLengthTextField.addActionListener(ae -> {
        String srcRecLen = sourceRecordLengthTextField.getText();
        try {
            Integer.parseInt(srcRecLen);
        } catch (NumberFormatException nfe) {
            // If the user enters non-integer text, take default value
            srcRecLen = "80";
        }
        sourceRecordLengthTextField.setText(srcRecLen);
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.setProperty("SOURCE_RECORD_LENGTH", srcRecLen);
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Connect/Reconnect button action
    // -------------------------------
    connectReconnectButton.addActionListener(ae -> {
        connectReconnectRefresh();
    });
    // 
    // PC charset combo box
    // --------------------
    // Select charset name from the list in combo box - listener
    pcCharComboBox.addItemListener(il -> {
        JComboBox source = (JComboBox) il.getSource();
        pcCharset = (String) source.getSelectedItem();
        if (!pcCharset.equals("*DEFAULT")) {
            // Check if charset is valid
            try {
                Charset.forName(pcCharset);
            } catch (IllegalCharsetNameException | UnsupportedCharsetException charset) {
                // If pcCharset is invalid, take ISO-8859-1
                pcCharset = "ISO-8859-1";
                pcCharComboBox.setSelectedItem(pcCharset);
            }
        }
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            properties.setProperty("PC_CHARSET", pcCharset);
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
    });
    // 
    // IBM i CCSID combo box item listener
    // ---------------------
    ibmCcsidComboBox.addItemListener(il -> {
        JComboBox source = (JComboBox) il.getSource();
        ibmCcsid = (String) source.getSelectedItem();
        if (!ibmCcsid.equals("*DEFAULT")) {
            try {
                ibmCcsidInt = Integer.parseInt(ibmCcsid);
            } catch (Exception exc) {
                exc.printStackTrace();
                ibmCcsid = "37";
                ibmCcsidInt = 37;
                ibmCcsidComboBox.setSelectedItem(ibmCcsid);
            }
        }
        // Create the updated text file in directory "paramfiles"
        try {
            infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
            properties.load(infile);
            infile.close();
            outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
            properties.setProperty("IBM_CCSID", ibmCcsid);
            properties.store(outfile, PROP_COMMENT);
            outfile.close();
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    });
    // 
    // Source record pattern check box - Yes = "Y", No = ""
    // ---------------------------------------------------
    sourceRecordPrefixCheckBox.addItemListener(il -> {
        Object source = il.getSource();
        if (source == sourceRecordPrefixCheckBox) {
            String check;
            if (sourceRecordPrefixCheckBox.isSelected()) {
                check = "Y";
            } else {
                check = "";
            }
            // Create the updated text file in directory "paramfiles"
            try {
                infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
                properties.load(infile);
                infile.close();
                outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
                properties.setProperty("SOURCE_RECORD_PREFIX", check);
                properties.store(outfile, PROP_COMMENT);
                outfile.close();
            } catch (Exception exc) {
                exc.printStackTrace();
            }
        }
    });
    // 
    // Overwrite output file(s) check box - Yes = "Y", No = ""
    // -------------------------------------------------------
    overwriteOutputFileCheckBox.addItemListener(il -> {
        Object source = il.getSource();
        if (source == overwriteOutputFileCheckBox) {
            String check;
            if (overwriteOutputFileCheckBox.isSelected()) {
                check = "Y";
            } else {
                check = "";
            }
            // Create the updated text file in directory "paramfiles"
            try {
                infile = Files.newBufferedReader(parPath, Charset.forName(encoding));
                properties.load(infile);
                infile.close();
                outfile = Files.newBufferedWriter(parPath, Charset.forName(encoding));
                properties.setProperty("OVERWRITE_FILE", check);
                properties.store(outfile, PROP_COMMENT);
                outfile.close();
            } catch (Exception exc) {
                exc.printStackTrace();
            }
        }
    });
    // 
    // Left popup menu on Right mouse click
    // ====================================
    // 
    // Find text in multiple PC files
    // 
    findInPcFiles.addActionListener(ae -> {
        copySourceTree = leftTree;
        // Set clipboard path string for find operation
        clipboardPathStrings = leftPathStrings;
        SearchWindow searchWindow = new SearchWindow(remoteServer, this, "PC");
    });
    // 
    // Send to remote server (IBM i)
    // 
    copyFromLeft.addActionListener(ae -> {
        copySourceTree = leftTree;
        // Set clipboard path string for paste operation
        clipboardPathStrings = leftPathStrings;
    });
    // 
    // Receive from remote server (IBM i) or PC itself
    // 
    pasteToLeft.addActionListener(ae -> {
        if (copySourceTree == rightTree) {
            row = "Wait: Copying from IBM i to PC . . .";
            msgVector.add(row);
            showMessages();
            // Paste from IBM i to PC
            ParallelCopy_IBMi_PC parallelCopy_IMBI_PC = new ParallelCopy_IBMi_PC(remoteServer, clipboardPathStrings, leftPathStrings[0], null, this);
            parallelCopy_IMBI_PC.execute();
        } else if (copySourceTree == leftTree) {
            row = "Wait: Copying from PC to PC . . .";
            msgVector.add(row);
            showMessages(nodes);
            // Paste from PC to PC
            ParallelCopy_PC_PC parallelCopy_PC_PC = new ParallelCopy_PC_PC(clipboardPathStrings, leftPathStrings[0], null, this);
            parallelCopy_PC_PC.execute();
        }
    });
    // Insert spooled file that is copied from directory *workfiles* and, renamed,
    // into selected directory *targetPathString*
    insertSpooledFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        sourcePathString = Paths.get(System.getProperty("user.dir"), "workfiles", "SpooledFile.txt").toString();
        targetPathString = leftPathStrings[0];
        copyAndRenameFile("SpooledFile.txt");
        reloadLeftSide(nodes);
    });
    // Display PC file
    displayPcFile.addActionListener(ae -> {
        clipboardPathStrings = leftPathStrings;
        // Display all selected files
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            sourcePathString = clipboardPathStrings[idx];
            JTextArea textArea = new JTextArea();
            // This is a way to display a PC file directly from Java:
            DisplayFile dspf = new DisplayFile(textArea, this);
            dspf.displayPcFile(sourcePathString);
        }
    });
    // Edit PC file
    editPcFile.addActionListener(ae -> {
        clipboardPathStrings = leftPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            sourcePathString = clipboardPathStrings[idx];
            JTextArea textArea = new JTextArea();
            JTextArea textArea2 = new JTextArea();
            EditFile edtf = new EditFile(remoteServer, this, textArea, textArea2, leftPathString, "rewritePcFile");
        }
    });
    // Rename PC file
    renamePcFile.addActionListener(ae -> {
        RenamePcObject rnmpf = new RenamePcObject(this, pcFileSep, currentX, currentY);
        rnmpf.renamePcObject(leftPathString);
    });
    // Create PC directory
    createPcDirectory.addActionListener(ae -> {
        clipboardPathStrings = leftPathStrings;
        if (clipboardPathStrings.length > 0) {
            leftPathString = clipboardPathStrings[0];
            CreateAndDeleteInPC cpcd = new CreateAndDeleteInPC(this, "createPcDirectory", currentX, currentY);
            cpcd.createAndDeleteInPC();
            reloadLeftSide(nodes);
        }
    });
    // Create PC file
    createPcFile.addActionListener(ae -> {
        CreateAndDeleteInPC cpcf = new CreateAndDeleteInPC(this, "createPcFile", currentX, currentY);
        cpcf.createAndDeleteInPC();
        reloadLeftSide(nodes);
    });
    // Move PC objects to trash
    movePcObjectToTrash.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Move selected objects to trash
        // ------------------------------
        // Set clipboard path strings for paste operation
        clipboardPathStrings = leftPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            // Set path string for the following class
            leftPathString = clipboardPathStrings[idx];
            // Move one object to trash
            CreateAndDeleteInPC dpco = new CreateAndDeleteInPC(this, "movePcObjectToTrash", currentX, currentY);
            dpco.createAndDeleteInPC();
        }
        // Remove selected nodes
        TreePath[] paths = leftTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            leftNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            leftTreeModel.removeNodeFromParent(leftNode);
        }
    });
    // 
    // Right popup menu on Right mouse click
    // =====================================
    // 
    // Find text in multiple IFS files
    // 
    findInIfsFiles.addActionListener(ae -> {
        copySourceTree = rightTree;
        // Set clipboard path string for find operation
        clipboardPathStrings = rightPathStrings;
        SearchWindow searchWindow = new SearchWindow(remoteServer, this, "IFS");
    });
    // Send to PC or IBM i itself
    copyFromRight.addActionListener(ae -> {
        copySourceTree = rightTree;
        // Set clipboard path string for paste operation
        clipboardPathStrings = rightPathStrings;
    });
    // Receive from PC or IBM i itself
    // -------------------------------
    pasteToRight.addActionListener(ae -> {
        // This listener keeps the scroll pane at the LAST MESSAGE.
        // It is removed at the end of the method of the background task.
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        sourcePathString = clipboardPathString;
        targetPathString = rightPathStrings[0];
        if (copySourceTree == rightTree) {
            // Paste from IBM i to IBM i
            row = "Wait: Copying from IBM i to IBM i . . .";
            msgVector.add(row);
            showMessages();
            ParallelCopy_IBMi_IBMi parallelCopy_IMBI_IBMI = new ParallelCopy_IBMi_IBMi(remoteServer, clipboardPathStrings, targetPathString, null, this);
            parallelCopy_IMBI_IBMI.execute();
        } else if (copySourceTree == leftTree) {
            // Paste from PC to IBM i
            row = "Wait: Copying from PC to IBM i . . .";
            msgVector.add(row);
            showMessages();
            ParallelCopy_PC_IBMi parallelCopy_PC_IBMI = new ParallelCopy_PC_IBMi(remoteServer, clipboardPathStrings, targetPathString, null, this);
            parallelCopy_PC_IBMI.execute();
        }
    });
    // Copy library
    copyLibrary.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "copyLibrary", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
        reloadRightSide();
    });
    // Clear library
    clearLibrary.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Set clipboard path strings for paste operation
        clipboardPathStrings = rightPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            rightPathString = clipboardPathStrings[idx];
            ifsFile = new IFSFile(remoteServer, rightPathString);
            // Clear selected libraries
            // ------------------------
            CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "clearLibrary", currentX, currentY);
            crtdlt.createAndDeleteInIBMi(currentX, currentY);
        }
        // Reload nodes of cleared libraries
        TreePath[] paths = rightTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            reloadRightSide();
        }
    });
    // Delete library
    deleteLibrary.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Set clipboard path strings for paste operation
        clipboardPathStrings = rightPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            rightPathString = clipboardPathStrings[idx];
            ifsFile = new IFSFile(remoteServer, rightPathString);
            // Delete selected libraries
            // -------------------------
            CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteLibrary", currentX, currentY);
            crtdlt.createAndDeleteInIBMi(currentX, currentY);
        }
        // Remove selected nodes
        TreePath[] paths = rightTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            rightTreeModel.removeNodeFromParent(rightNode);
        }
    });
    // Create IFS directory in a parent directory
    createIfsDirectory.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createIfsDirectory", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
        reloadRightSide();
    });
    // Create IFS directory in a parent directory
    createIfsFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createIfsFile", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
        reloadRightSide();
    });
    // Create AS400 Source Physical File
    createSourcePhysicalFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createSourcePhysicalFile", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
        reloadRightSide();
    });
    // Create AS400 Source Member
    createSourceMember.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createSourceMember", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
        reloadRightSide();
    });
    // Create Save File
    createSaveFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "createSaveFile", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
        reloadRightSide();
    });
    // Clear Save File
    clearSaveFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        ifsFile = new IFSFile(remoteServer, rightPathString);
        CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "clearSaveFile", currentX, currentY);
        crtdlt.createAndDeleteInIBMi(currentX, currentY);
    });
    // Delete IFS object (directory or file)
    deleteIfsObject.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Delete selected objects
        // -----------------------
        // Set clipboard path strings for paste operation
        clipboardPathStrings = rightPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            rightPathString = clipboardPathStrings[idx];
            ifsFile = new IFSFile(remoteServer, rightPathString);
            CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteIfsObject", currentX, currentY);
            crtdlt.createAndDeleteInIBMi(currentX, currentY);
        }
        // Remove selected nodes
        TreePath[] paths = rightTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            rightTreeModel.removeNodeFromParent(rightNode);
        }
    });
    // Delete AS400 Source Member
    deleteSourceMember.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Set clipboard path strings for paste operation
        clipboardPathStrings = rightPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            rightPathString = clipboardPathStrings[idx];
            ifsFile = new IFSFile(remoteServer, rightPathString);
            // Delete selected objects
            // -----------------------
            CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteSourceMember", currentX, currentY);
            crtdlt.createAndDeleteInIBMi(currentX, currentY);
        }
        // Remove selected nodes
        TreePath[] paths = rightTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            rightTreeModel.removeNodeFromParent(rightNode);
        }
    });
    // Delete AS400 Source Physical File
    deleteSourcePhysicalFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Set clipboard path strings for paste operation
        clipboardPathStrings = rightPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            rightPathString = clipboardPathStrings[idx];
            ifsFile = new IFSFile(remoteServer, rightPathString);
            // Delete selected objects
            // -----------------------
            CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteSourcePhysicalFile", currentX, currentY);
            crtdlt.createAndDeleteInIBMi(currentX, currentY);
        }
        // Remove selected nodes
        TreePath[] paths = rightTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            rightTreeModel.removeNodeFromParent(rightNode);
        }
    });
    // Delete Save File
    deleteSaveFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        // Set clipboard path strings for paste operation
        clipboardPathStrings = rightPathStrings;
        for (int idx = 0; idx < clipboardPathStrings.length; idx++) {
            rightPathString = clipboardPathStrings[idx];
            ifsFile = new IFSFile(remoteServer, rightPathString);
            // Delete selected objects
            // -----------------------
            CreateAndDeleteInIBMi crtdlt = new CreateAndDeleteInIBMi(remoteServer, ifsFile, this, "deleteSaveFile", currentX, currentY);
            crtdlt.createAndDeleteInIBMi(currentX, currentY);
        }
        // Remove selected nodes
        TreePath[] paths = rightTree.getSelectionPaths();
        for (int indx = 0; indx < paths.length; indx++) {
            rightNode = (DefaultMutableTreeNode) (paths[indx].getLastPathComponent());
            rightTreeModel.removeNodeFromParent(rightNode);
        }
    });
    // Work with spooled files
    workWithSpooledFiles.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        String className = this.getClass().getSimpleName();
        // first "false" stands for *ALL users (not *CURRENT user),
        // second "true" stands for "create spooled file table".
        WrkSplFCall wwsp = new WrkSplFCall(remoteServer, this, rightPathString, // not *CURRENT user
        false, currentX, currentY, className, // create spooled file table
        true);
        wwsp.execute();
    });
    // Display IFS file
    displayIfsFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        JTextArea textArea = new JTextArea();
        DisplayFile dspf = new DisplayFile(textArea, this);
        dspf.displayIfsFile(remoteServer, rightPathString);
    });
    // Edit IFS file with source types suffix (e.g. .CLLE, .RPGLE, etc.)
    editIfsFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        JTextArea textArea = new JTextArea();
        JTextArea textArea2 = new JTextArea();
        EditFile edtf = new EditFile(remoteServer, this, textArea, textArea2, rightPathString, "rewriteIfsFile");
    });
    // Rename IFS file
    renameIfsFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        RenameIfsObject rnmifsf = new RenameIfsObject(remoteServer, this, currentX, currentY);
        rnmifsf.renameIfsObject(rightPathString);
    });
    // Compile IFS file
    compileIfsFile.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        if (compile == null) {
            compile = new Compile(remoteServer, this, rightPathString, true);
        }
        // "true" stands for "IFS file" as a source text
        compile.compile(rightPathString, true);
    // compile = null;
    });
    // Display IBM i Source Member
    displaySourceMember.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        JTextArea textArea = new JTextArea();
        DisplayFile dspf = new DisplayFile(textArea, this);
        dspf.displaySourceMember(remoteServer, rightPathString);
    });
    // Edit IBM i Source Member
    editSourceMember.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        JTextArea textArea = new JTextArea();
        JTextArea textArea2 = new JTextArea();
        EditFile edtf = new EditFile(remoteServer, this, textArea, textArea2, rightPathString, "rewriteSourceMember");
    });
    // Compile Source Member
    compileSourceMember.addActionListener(ae -> {
        scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
        if (compile == null) {
            compile = new Compile(remoteServer, this, rightPathString, false);
        }
        // "false" means "IFS file" is NOT a source text
        compile.compile(rightPathString, false);
    // compile = null;
    });
    // 
    // Find text in multiple Source Members
    // 
    findInSourceMembers.addActionListener(ae -> {
        copySourceTree = rightTree;
        // Set clipboard path string for find operation
        clipboardPathStrings = rightPathStrings;
        SearchWindow searchWindow = new SearchWindow(remoteServer, this, "MBR");
    });
    // =================
    if (operatingSystem.equals(WINDOWS)) {
        // Item listener for DISKS ComboBox reacts on item selection with
        // the
        // mouse
        disksComboBox.addItemListener(il -> {
            JComboBox<String> comboBox = (JComboBox) il.getSource();
            leftPathString = (String) comboBox.getSelectedItem();
            // Remove the old and create a new combo box for left path selection
            panelPathLeft.remove(leftPathComboBox);
            leftPathComboBox = new JComboBox<>();
            leftPathComboBox.setEditable(true);
            panelPathLeft.add(leftPathComboBox);
            leftPathComboBox.addItem(leftPathString);
            leftPathComboBox.setSelectedIndex(0);
            // Register a new ActionListener to the new combo box
            leftPathComboBox.addActionListener(leftPathActionListener);
            // Get the first item (disk symbol or file system root) from the
            // combo box and make it leftRoot
            leftRoot = leftPathString;
            // Make the disk symbol also firstLeftRootSymbol
            firstLeftRootSymbol = leftPathString;
            // Clear and set the tree map with leftRoot and row number 0
            leftTreeMap.clear();
            leftTreeMap.put(leftRoot, 0);
            // Create a new tree and table on the left side of the window
            leftRootChanged = true;
            createNewLeftSide(leftPathString);
        });
    }
    // End Windows
    // Processing continues for both Windows and Unix:
    // 
    // Register action listener for LEFT PATH ComboBox reacts on text change
    // in its input field (first time)
    leftPathComboBox.addActionListener(leftPathActionListener);
    // Component listener reacting to WINDOW RESIZING
    ComponentListener resizingListener = new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent componentEvent) {
            windowWidth = componentEvent.getComponent().getWidth();
            windowHeight = componentEvent.getComponent().getHeight();
            // 50 %
            double splitPaneInnerDividerLoc = 0.50d;
            // int splitPaneInnerDividerLoc = (windowWidth - (2 * borderWidth + 5)) / 2;
            splitPaneInner.setDividerLocation(splitPaneInnerDividerLoc);
        }
    };
    // Register window resizing listener
    addComponentListener(resizingListener);
    // Add the global panel to the frame, NOT container
    cont.add(globalPanel);
    add(globalPanel);
    // Set initial size and width of the window
    setSize(windowWidth, windowHeight);
    // Set window coordinates from application properties
    setLocation(mainWindowX, mainWindowY);
    // Show the window on the screen
    setVisible(true);
    // Do not pack
    pack();
}
Also used : JPanel(javax.swing.JPanel) ComponentListener(java.awt.event.ComponentListener) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) ComponentEvent(java.awt.event.ComponentEvent) JSplitPane(javax.swing.JSplitPane) IFSFile(com.ibm.as400.access.IFSFile) BoxLayout(javax.swing.BoxLayout) URI(java.net.URI) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) GroupLayout(javax.swing.GroupLayout) JMenuItem(javax.swing.JMenuItem) Component(java.awt.Component) JComponent(javax.swing.JComponent) ComponentAdapter(java.awt.event.ComponentAdapter) JScrollPane(javax.swing.JScrollPane) JComboBox(javax.swing.JComboBox) JLabel(javax.swing.JLabel) IOException(java.io.IOException) Point(java.awt.Point) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) IllegalCharsetNameException(java.nio.charset.IllegalCharsetNameException) IOException(java.io.IOException) TreePath(javax.swing.tree.TreePath) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 5 with Record

use of com.ibm.as400.access.Record in project IBMiProgTool by vzupka.

the class SearchWindow method readSourceMember.

/**
 * Read Source Member data into text area.
 *
 * @return
 */
protected JTextArea readSourceMember() {
    IFSFile ifsFile = new IFSFile(remoteServer, mainWindow.sourcePathString);
    // Create an AS400FileRecordDescription object that represents the file
    AS400FileRecordDescription inRecDesc = new AS400FileRecordDescription(remoteServer, mainWindow.sourcePathString);
    try {
        // Decide what CCSID is appropriate for displaying the member
        int ccsidAttribute = ifsFile.getCCSID();
        // Get list of record formats of the database file
        RecordFormat[] format = inRecDesc.retrieveRecordFormat();
        // Create an AS400File object that represents the file
        SequentialFile as400seqFile = new SequentialFile(remoteServer, mainWindow.sourcePathString);
        // Set the record format (the only one)
        as400seqFile.setRecordFormat(format[0]);
        // Open the source physical file member as a sequential file
        as400seqFile.open(AS400File.READ_ONLY, 0, AS400File.COMMIT_LOCK_LEVEL_NONE);
        // Read the first source member record
        Record inRecord = as400seqFile.readNext();
        // --------------------
        while (inRecord != null) {
            StringBuilder textLine = new StringBuilder();
            // Source record is composed of three source record fields: seq.
            // number, date, source data.
            DecimalFormat df1 = new DecimalFormat("0000.00");
            DecimalFormat df2 = new DecimalFormat("000000");
            // Sequence number - 6 bytes
            String seq = df1.format((Number) inRecord.getField("SRCSEQ"));
            String seq2 = seq.substring(0, 4) + seq.substring(5);
            textLine.append(seq2);
            // Date - 6 bytes
            String srcDat = df2.format((Number) inRecord.getField("SRCDAT"));
            // textLine.append(srcDat);
            textLine.append(srcDat);
            // Data from source record (the source line)
            byte[] bytes = inRecord.getFieldAsBytes("SRCDTA");
            // Create object for conversion from bytes to characters
            // Ignore "IBM i CCSID" parameter - display characters in the
            // member.
            AS400Text textConverter = new AS400Text(bytes.length, remoteServer);
            // Convert byte array buffer to text line (String - UTF-16)
            String translatedData = (String) textConverter.toObject(bytes);
            // Append translated data to text line
            textLine.append(translatedData).append(NEW_LINE);
            // Append text line to text area
            textArea.append(textLine.toString());
            // Read next source member record
            inRecord = as400seqFile.readNext();
        }
        // Close the file
        as400seqFile.close();
        // Set scroll bar to top
        textArea.setCaretPosition(0);
        // Display the window.
        setVisible(true);
        mainWindow.row = "Info: Source member  " + mainWindow.sourcePathString + "  has CCSID  " + ccsidAttribute + ".";
        mainWindow.msgVector.add(mainWindow.row);
        mainWindow.showMessages(mainWindow.nodes);
    } catch (Exception exc) {
        exc.printStackTrace();
        mainWindow.row = "Error: " + exc.toString();
        mainWindow.msgVector.add(mainWindow.row);
        mainWindow.showMessages(mainWindow.nodes);
    }
    // Remove message scroll listener (cancel scrolling to the last message)
    mainWindow.scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(mainWindow.messageScrollPaneAdjustmentListenerMax);
    return textArea;
}
Also used : SequentialFile(com.ibm.as400.access.SequentialFile) RecordFormat(com.ibm.as400.access.RecordFormat) DecimalFormat(java.text.DecimalFormat) PatternSyntaxException(java.util.regex.PatternSyntaxException) AS400FileRecordDescription(com.ibm.as400.access.AS400FileRecordDescription) AS400Text(com.ibm.as400.access.AS400Text) Record(com.ibm.as400.access.Record) IFSFile(com.ibm.as400.access.IFSFile)

Aggregations

IFSFile (com.ibm.as400.access.IFSFile)7 AS400FileRecordDescription (com.ibm.as400.access.AS400FileRecordDescription)6 Record (com.ibm.as400.access.Record)6 RecordFormat (com.ibm.as400.access.RecordFormat)6 SequentialFile (com.ibm.as400.access.SequentialFile)6 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)6 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)6 AS400Text (com.ibm.as400.access.AS400Text)5 CommandCall (com.ibm.as400.access.CommandCall)3 Point (java.awt.Point)3 DecimalFormat (java.text.DecimalFormat)3 BadLocationException (javax.swing.text.BadLocationException)3 AS400Message (com.ibm.as400.access.AS400Message)2 BufferedWriter (java.io.BufferedWriter)2 BigDecimal (java.math.BigDecimal)2 Path (java.nio.file.Path)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 JTextArea (javax.swing.JTextArea)2 CannotRedoException (javax.swing.undo.CannotRedoException)2 CannotUndoException (javax.swing.undo.CannotUndoException)2