Search in sources :

Example 41 with IFSFile

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

the class ChangeLibraryList method getListOfLibraries.

/**
 * Get list of all libraries whose names conform to the pattern defined in the input field
 *
 * @param libraryPattern
 * @return
 */
protected String[] getListOfLibraries(String libraryPattern) {
    libraryField = libraryPattern;
    if (libraryField.isEmpty()) {
        libraryPattern = "*";
    }
    libraryWildCard = libraryPattern.replace("*", ".*");
    libraryWildCard = libraryWildCard.replace("?", ".");
    IFSFile ifsFile = new IFSFile(remoteServer, "/QSYS.LIB");
    if (ifsFile.getName().equals("QSYS.LIB")) {
        try {
            // Get list of subfiles/subdirectories
            IFSFile[] ifsFiles2 = ifsFile.listFiles();
            vectorLeft.removeAllElements();
            for (IFSFile ifsFileLevel2 : ifsFiles2) {
                if (ifsFileLevel2.toString().endsWith(".LIB")) {
                    String bareLibraryName = ifsFileLevel2.getName().substring(0, ifsFileLevel2.getName().indexOf("."));
                    if (bareLibraryName.matches(libraryWildCard)) {
                        vectorLeft.addElement(bareLibraryName);
                    }
                }
            }
            // Fill the left list with library names
            listLeft.setListData(vectorLeft);
            // Set the left list as enabled for dragging from.
            listLeft.setDragEnabled(true);
        } catch (Exception exc) {
            exc.printStackTrace();
        }
    }
    String[] strArr = new String[vectorLeft.size()];
    strArr = vectorLeft.toArray(strArr);
    return strArr;
}
Also used : IOException(java.io.IOException) IFSFile(com.ibm.as400.access.IFSFile)

Example 42 with IFSFile

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

the class SearchWindow method readIfsFile.

/**
 * Read IFS file data into text area.
 *
 * @return
 */
protected JTextArea readIfsFile() {
    try {
        IFSFile ifsFile = new IFSFile(remoteServer, mainWindow.sourcePathString);
        int attributeCCSID = ifsFile.getCCSID();
        byte[] inputBuffer = new byte[100000];
        byte[] workBuffer = new byte[100000];
        try (IFSFileInputStream inputStream = new IFSFileInputStream(remoteServer, mainWindow.sourcePathString)) {
            int bytesRead = inputStream.read(inputBuffer);
            while (bytesRead != -1) {
                for (int idx = 0; idx < bytesRead; idx++) {
                    // Copy input byte to output byte
                    workBuffer[idx] = inputBuffer[idx];
                }
                // Copy the printable part of the work array to a new buffer that will be written out.
                byte[] bufferToWrite = new byte[bytesRead];
                // Copy bytes from the work buffer to the new buffer
                for (int indx = 0; indx < bytesRead; indx++) {
                    bufferToWrite[indx] = workBuffer[indx];
                }
                // Create object for conversion from bytes to characters
                AS400Text textConverter = new AS400Text(bytesRead, attributeCCSID, remoteServer);
                // Convert byte array buffer to text line
                String textLine = (String) textConverter.toObject(bufferToWrite);
                // Append the line to text area
                textArea.append(textLine + NEW_LINE);
                // Read next input buffer
                bytesRead = inputStream.read(inputBuffer);
            }
            mainWindow.row = "Info: IFS file  " + mainWindow.sourcePathString + "  has CCSID  " + attributeCCSID + ".";
            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 : AS400Text(com.ibm.as400.access.AS400Text) PatternSyntaxException(java.util.regex.PatternSyntaxException) IFSFile(com.ibm.as400.access.IFSFile) IFSFileInputStream(com.ibm.as400.access.IFSFileInputStream)

Example 43 with IFSFile

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

the class MainWindow method reloadRightSide.

/**
 * Reload node structure in the right side of the window.
 */
protected void reloadRightSide() {
    ifsFile = new IFSFile(remoteServer, rightPathString);
    // Add IFS nodes (children) for the right tree in parallel background process
    AddAS400Nodes an = new AddAS400Nodes(ifsFile, rightNode, this);
    an.execute();
}
Also used : IFSFile(com.ibm.as400.access.IFSFile)

Example 44 with IFSFile

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

the class MainWindow method expandRightTreeNode.

/**
 * Expand right tree node after change.
 *
 * @param info
 */
protected void expandRightTreeNode(TransferHandler.TransferSupport info) {
    IFSFile targetPath = new IFSFile(remoteServer, targetPathString);
    // Target node
    // -----------
    targetNode = (DefaultMutableTreeNode) rightTree.getLastSelectedPathComponent();
    // Add target node for inserted children
    if (targetNode != null) {
        // Add IFS nodes (children) for the right tree in parallel background process
        AddAS400Nodes an = new AddAS400Nodes(targetPath, targetNode, this);
        an.execute();
    }
    // Get coordinates of target node
    TransferHandler.DropLocation dropLocation = info.getDropLocation();
    double dropX = dropLocation.getDropPoint().getX();
    double dropY = dropLocation.getDropPoint().getY();
    // Get index from coordinates of the drop node
    rightRow = rightTree.getRowForLocation((int) dropX, (int) dropY);
    // Expand that node on that index
    rightTree.expandRow(rightRow);
    // Note that the children were added
    rightTreeModel.nodeStructureChanged(targetNode);
}
Also used : TransferHandler(javax.swing.TransferHandler) IFSFile(com.ibm.as400.access.IFSFile)

Aggregations

IFSFile (com.ibm.as400.access.IFSFile)44 IllegalCharsetNameException (java.nio.charset.IllegalCharsetNameException)14 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)14 AS400Text (com.ibm.as400.access.AS400Text)11 CommandCall (com.ibm.as400.access.CommandCall)9 AS400Message (com.ibm.as400.access.AS400Message)8 Path (java.nio.file.Path)7 AS400FileRecordDescription (com.ibm.as400.access.AS400FileRecordDescription)5 IFSFileInputStream (com.ibm.as400.access.IFSFileInputStream)5 Record (com.ibm.as400.access.Record)5 RecordFormat (com.ibm.as400.access.RecordFormat)5 SequentialFile (com.ibm.as400.access.SequentialFile)5 BadLocationException (javax.swing.text.BadLocationException)5 Point (java.awt.Point)4 PatternSyntaxException (java.util.regex.PatternSyntaxException)4 IFSFileOutputStream (com.ibm.as400.access.IFSFileOutputStream)3 DecimalFormat (java.text.DecimalFormat)3 CannotRedoException (javax.swing.undo.CannotRedoException)3 CannotUndoException (javax.swing.undo.CannotUndoException)3 BufferedWriter (java.io.BufferedWriter)2