use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class MainWindow method createNewRightSide.
/**
* Create the IBM i file tree on the right side of the window;
* IBM i files are objects and differ conceptually from PC files,
* therefore they are processed differently.
*
* @param currentRightRoot
*/
protected void createNewRightSide(String currentRightRoot) {
// Set wait-cursor (rotating wheel?)
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
// Keeps the scroll pane at the LAST MESSAGE.
scrollMessagePane.getVerticalScrollBar().addAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
// Set file system root symbol to the combo box
// rightPathComboBox.addItem(currentRightRoot);
// Right tree showing IBM i file system (IFS)
// ----------
rightPathString = currentRightRoot;
rightTopNode = new DefaultMutableTreeNode(currentRightRoot);
rightTreeMap.put(currentRightRoot, 0);
// Create right hand tree
rightTree = new JTree(rightTopNode);
// Create tree model
rightTreeModel = (DefaultTreeModel) rightTree.getModel();
// Mouse listener for RIGHT TREE reacts on row number selected by mouse
// left or right click
rightTreeMouseListener = new RightTreeMouseAdapter();
rightTree.addMouseListener(rightTreeMouseListener);
rightTree.setDragEnabled(true);
rightTree.setDropMode(DropMode.USE_SELECTION);
rightTree.setTransferHandler(new RightTreeTransferHandler(this));
rightTreeSelModel = rightTree.getSelectionModel();
rightTreeSelModel.setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
rightRowMapper = rightTreeSelModel.getRowMapper();
rightTree.setRootVisible(true);
rightTree.setShowsRootHandles(true);
rightTree.setSelectionRow(0);
rightPathString = correctRightPathString(rightPathString);
// Right root must start with a slash
if (!rightPathString.startsWith("/")) {
// Show error message when the path string does not start with a slash.
row = "Error: Right path string " + rightPathString + " does not start with a slash. " + "Correct the path string and try again.";
msgVector.add(row);
showMessages(noNodes);
// Change cursor to default
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
// Remove setting last element of messages
scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
return;
}
if (remoteServer == null) {
row = "Error: Connection to server " + properties.getProperty("HOST") + " failed!!!!!!.";
msgVector.add(row);
showMessages(noNodes);
// Change cursor to default
setCursor(Cursor.getDefaultCursor());
// Remove setting last element of messages
scrollMessagePane.getVerticalScrollBar().removeAdjustmentListener(messageScrollPaneAdjustmentListenerMax);
} else {
// Create an object of IFSFile from the path string for adding nodes
ifsFile = new IFSFile(remoteServer, rightPathString);
// Add IFS nodes for the right tree in parallel background process
// -------------
AddAS400Nodes an = new AddAS400Nodes(ifsFile, rightTopNode, this);
an.execute();
// No statements may be here!
}
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class RenameIfsObject method renameIfsObject.
/**
* Rename IFS file.
*
* @param oldPathString
*/
protected void renameIfsObject(String oldPathString) {
GetTextFromDialog getText = new GetTextFromDialog("RENAME");
String oldFilePrefix = oldPathString.substring(0, oldPathString.lastIndexOf("/"));
String oldFileName = oldPathString.substring(oldPathString.lastIndexOf("/") + 1);
// "false" stands for not changing result to upper case
String newFileName = getText.getTextFromDialog("Parent directory", "New name:", oldFilePrefix, oldFileName, false, currentX, currentY);
if (newFileName == null) {
return;
}
if (newFileName.isEmpty()) {
newFileName = oldFileName;
}
if (oldPathString.startsWith("/QSYS.LIB")) {
// Object name in library cannot be longer than 10 characters
String nameWithoutSuffix = newFileName.substring(0, newFileName.lastIndexOf("."));
String suffix = newFileName.substring(newFileName.lastIndexOf("."));
if (nameWithoutSuffix.length() > 10) {
nameWithoutSuffix = nameWithoutSuffix.substring(0, 10);
}
newFileName = nameWithoutSuffix + suffix;
newFileName = newFileName.toUpperCase();
}
String renamedPathString = oldFilePrefix + "/" + newFileName;
try {
// Create IFSFile objects
// Old IFS file
IFSFile oldIfsFile = new IFSFile(remoteServer, oldPathString);
// New IFS file
IFSFile newIfsFile = new IFSFile(remoteServer, renamedPathString);
// Rename the old to new IFS file
boolean renamed = oldIfsFile.renameTo(newIfsFile);
// If not renamed for any error, send message
if (!renamed) {
row = "Error: Renaming IFS file " + oldPathString + " to " + renamedPathString + " failed.";
mainWindow.msgVector.add(row);
// "false" stands for "no update of tree node"
mainWindow.showMessages();
return;
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Renaming IFS file - " + exc.toString();
mainWindow.msgVector.add(row);
// "false" stands for "no update of tree node"
mainWindow.showMessages();
}
// Change left node (source node selected by mouse click)
mainWindow.rightNode.setUserObject(newFileName);
mainWindow.leftTreeModel.nodeChanged(mainWindow.rightNode);
// Send completion message
row = "Comp: IFS file " + oldPathString + " was renamed to " + renamedPathString + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Compile 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 selected libraries
IFSFile[] ifsFiles = ifsFile.listFiles(libraryPattern + ".LIB");
libraryNameVector.removeAllElements();
// Add the selected library names to the vector
for (IFSFile ifsFileLevel2 : ifsFiles) {
String bareLibraryName = ifsFileLevel2.getName().substring(0, ifsFileLevel2.getName().indexOf("."));
libraryNameVector.addElement(bareLibraryName);
}
// Add "current library"
libraryNameVector.addElement("*CURLIB");
} catch (Exception exc) {
exc.printStackTrace();
}
}
String[] libraryArray = new String[libraryNameVector.size()];
libraryArray = libraryNameVector.toArray(libraryArray);
return libraryArray;
}
use of com.ibm.as400.access.IFSFile 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;
}
use of com.ibm.as400.access.IFSFile in project IBMiProgTool by vzupka.
the class Copy_IBMi_IBMi method copyFromIfsDirectory.
/**
* Copy IFS directory to Source file;
*
* @param sourcePathString
* @param targetPathString
* @param sourcePathStringPrefix
* @return
*/
protected String copyFromIfsDirectory(String sourcePathString, String targetPathString, String sourcePathStringPrefix) {
// Cannot copy to itself
if (targetPathString.equals(sourcePathString)) {
return null;
}
// Path to input IFS file
inputDirFile = new IFSFile(remoteServer, sourcePathString);
// Path to output IFS file
outputDirFile = new IFSFile(remoteServer, targetPathString);
try {
// ---------------
if (targetPathString.startsWith("/QSYS.LIB/")) {
if (outputDirFile.isDirectory()) {
// ---------------------------------------
if (targetPathString.endsWith(".LIB")) {
// Copy IFS directory to a Library is not allowed.
row = "Error: Copying IFS directory to Library is not allowed. " + "First create a source physial file with a CCSID of your choice.";
mainWindow.msgVector.add(row);
mainWindow.showMessages();
return "ERROR";
}
// -------------------------------------------
if (outputDirFile.isSourcePhysicalFile()) {
msgText = copyToSourceFile(remoteServer, sourcePathString, targetPathString);
}
return msgText;
}
}
} catch (Exception exc) {
exc.printStackTrace();
row = "Error: Copying " + sourcePathString + " to " + targetPathString + " - " + exc.toString() + ".";
mainWindow.msgVector.add(row);
mainWindow.showMessages(nodes);
}
return "";
}
Aggregations