archimate.util
Class FileHandler

java.lang.Object
  extended by archimate.util.FileHandler

public class FileHandler
extends java.lang.Object

Utility class for handling source files

Author:
Samuel Esposito

Constructor Summary
FileHandler()
           
 
Method Summary
 int countFiles(java.lang.String packageBase)
          Counts the number of source files in a Java project source folder.
 org.eclipse.core.resources.IContainer findOrCreateContainer(java.lang.String packageName)
          Finds or creates a container for the specified directory and package
 java.lang.String getSource(org.eclipse.core.resources.IFile file)
          Gets the contents of a file and returns it as a string.
 void openResource(org.eclipse.core.resources.IResource resource)
          Opens the newly created file in a new editor in Eclipse
 org.eclipse.core.resources.IFile save(java.lang.String contents, org.eclipse.core.resources.IFile file)
          Saves the contents to an already opened file
 org.eclipse.core.resources.IFile save(java.lang.String contents, java.lang.String packageName, java.lang.String targetFile)
          Saves the specified contents to a location specified by the targetFolder, packageName and targetFile parameters.
 void selectAndReveal(org.eclipse.core.resources.IResource newResource)
          Reveals the newly created file in the Eclipse Package Explorer
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileHandler

public FileHandler()
Method Detail

countFiles

public int countFiles(java.lang.String packageBase)
Counts the number of source files in a Java project source folder.

Returns:
The number of files in a Java project source folder

getSource

public java.lang.String getSource(org.eclipse.core.resources.IFile file)
Gets the contents of a file and returns it as a string.

Parameters:
file - The file to be read
Returns:
The contents of the file

findOrCreateContainer

public org.eclipse.core.resources.IContainer findOrCreateContainer(java.lang.String packageName)
Finds or creates a container for the specified directory and package

Parameters:
packageName - The package to create the container in
Returns:
The found or newly created container

save

public org.eclipse.core.resources.IFile save(java.lang.String contents,
                                             java.lang.String packageName,
                                             java.lang.String targetFile)
Saves the specified contents to a location specified by the targetFolder, packageName and targetFile parameters. The location of the file to save is found by finding or creating the container (folder) for the package in the target folder. The name of the file to save is the target file.

Parameters:
contents - The contents of the file to save
packageName - The package the file is saved in
targetFile - The file name
Returns:
The saved file

save

public org.eclipse.core.resources.IFile save(java.lang.String contents,
                                             org.eclipse.core.resources.IFile file)
Saves the contents to an already opened file

Parameters:
contents - The contents string
file - The open file to write to
Returns:
The saved file

selectAndReveal

public void selectAndReveal(org.eclipse.core.resources.IResource newResource)
Reveals the newly created file in the Eclipse Package Explorer

Parameters:
newResource - The file to reveal

openResource

public void openResource(org.eclipse.core.resources.IResource resource)
Opens the newly created file in a new editor in Eclipse

Parameters:
resource - The resource to open