## org.eclipse.datatools.sqltools.sqlbuilder.util
Class WorkbenchUtility

    java.lang.Object
      org.eclipse.datatools.sqltools.sqlbuilder.util.WorkbenchUtility

    public class WorkbenchUtility

extends java.lang.Object

Field Summary
`static java.lang.String` `QUERY_DDL_EXTENSION`
`static java.lang.String` `QUERY_EXTENSION`
`static java.lang.String` `SQL_BUILDER_ID`
`static java.lang.String` `SQL_EDITOR_ID`

Constructor Summary
`WorkbenchUtility()`

Method Summary
`static org.eclipse.ui.IEditorPart` `getActiveEditor()` Gets the current editor.
`static int[]` `getSegments(int offset, java.lang.String text)` Searches a string and returns the segments containing qoutes '"'
`static java.util.List` `getSelectStatementsFromProject(org.eclipse.core.resources.IProject project, SQLDomainModel domainModel)` Gets a list of `QuerySelectStatement` objects contained within the given project.
`static org.eclipse.core.resources.IFile` `getSQLFileResource(java.lang.String projectName, java.lang.String resourceName)` Gets a SQL file resource with the given name in the given project.
`static org.eclipse.core.runtime.Path` `getSQLResourcePath(java.lang.String projectName, java.lang.String resourceName)` Gets a `Path` object for the given project name and SQL resource name.
`static org.eclipse.core.resources.IResource[]` `getSQLStatements(org.eclipse.core.resources.IProject aProj)` Get the SQL statements given a project.
`static void` `openEditor(org.eclipse.ui.IEditorInput editorInput, java.lang.String editorId)` Opens the given editor input object using the given editor.
`static void` `openEditor(org.eclipse.core.resources.IFile fileResource)` Opens the given file using the SQL Query Builder editor.
`static void` `openEditor(org.eclipse.core.resources.IFile fileResource, java.lang.String editorID)` Opens the given file using the given editor.
`static java.lang.String` `readFileContentsToString(org.eclipse.core.resources.IFile fileResource, boolean includeNewlines)` Returns the contents of the given file resource as a string, optionally including or suppressing newlines in the text.
`static boolean` `refreshLocalWorkspaceFile(org.eclipse.core.resources.IFile fileResource, org.eclipse.core.runtime.IProgressMonitor progressMonitor)` Refreshes the given file so it will be in synch with the local file system.
`static org.eclipse.core.resources.IFile` `saveStatementAsSQLFileResource(QueryStatement statement, java.lang.String projectName)` Saves the given SQL statement as a file resource in the given project.
`static void` `saveStringAsFileResource(org.eclipse.core.resources.IFile fileResource, java.lang.String content)` Saves the given string as the content of the given file resource.
`static org.eclipse.core.resources.IFile` `saveTextAsSQLFileResource(java.lang.String content, java.lang.String resourceName, java.lang.String projectName)` Saves the given string as the content as a SQL file resource with the given name in the given project.

Methods inherited from class java.lang.Object
`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

Field Detail

### SQL_BUILDER_ID

    public static final java.lang.String SQL_BUILDER_ID

See Also:
  Constant Field Values

### SQL_EDITOR_ID

    public static final java.lang.String SQL_EDITOR_ID

See Also:
  Constant Field Values

### QUERY_EXTENSION

    public static final java.lang.String QUERY_EXTENSION

See Also:
  Constant Field Values

### QUERY_DDL_EXTENSION

    public static final java.lang.String QUERY_DDL_EXTENSION

See Also:
  Constant Field Values

Constructor Detail

### WorkbenchUtility

    public WorkbenchUtility()

Method Detail

### getActiveEditor

    public static org.eclipse.ui.IEditorPart getActiveEditor()

  Gets the current editor.

  Returns:
    the current editor

### getSQLFileResource

    public static org.eclipse.core.resources.IFile getSQLFileResource(java.lang.String projectName,
                                                                      java.lang.String resourceName)

  Gets a SQL file resource with the given name in the given project. The file will have the extension ".sql".

  Parameters:
    `projectName` - the name of the project containing the statement
    `resourceName` - the name of the file resource to get
  Returns:
    the file resource or `null` if a file resource with for the given name cannot be opened

### getSQLResourcePath

    public static org.eclipse.core.runtime.Path getSQLResourcePath(java.lang.String projectName,
                                                                   java.lang.String resourceName)

  Gets a `Path` object for the given project name and SQL resource name. The path is formed as /projectName/resourceName.sql

  Parameters:
    `projectName` - the name of the project to use to create the path
    `resourceName` - the resource name to use to create the path
  Returns:
    the new `Path` object

### getSelectStatementsFromProject

    public static java.util.List getSelectStatementsFromProject(org.eclipse.core.resources.IProject project,
                                                                SQLDomainModel domainModel)

  Gets a list of `QuerySelectStatement` objects contained within the given project.

  Returns:
    the list of

### getSQLStatements

    public static org.eclipse.core.resources.IResource[] getSQLStatements(org.eclipse.core.resources.IProject aProj)

  Get the SQL statements given a project. Looks for resources in the project containing the "sql" or "ddl" file extension.

  Parameters:
    `aProj` - the database development project
  Returns:
    an array of IResources of SQL Statements.

### openEditor

    public static void openEditor(org.eclipse.ui.IEditorInput editorInput,
                                  java.lang.String editorId)

  Opens the given editor input object using the given editor. The editor is opened in a separate thread.

  Parameters:
    `editorInput` - the editor input for the editor to open
    `editorId` - the editor ID (defined in plugin.xml) of the editor to use

### openEditor

    public static void openEditor(org.eclipse.core.resources.IFile fileResource)

  Opens the given file using the SQL Query Builder editor.

  Parameters:
    `fileResource` - the file to open

### openEditor

    public static void openEditor(org.eclipse.core.resources.IFile fileResource,
                                  java.lang.String editorID)

  Opens the given file using the given editor.

  Parameters:
    `fileResource` - the file to open
    `editorID` - the editor ID (defined in plugin.xml) of the editor to use

### readFileContentsToString

    public static java.lang.String readFileContentsToString(org.eclipse.core.resources.IFile fileResource,
                                                            boolean includeNewlines)

  Returns the contents of the given file resource as a string, optionally including or suppressing newlines in the text. Returns an empty string if the file cannot be read.

  Parameters:
    `fileResource` - the file resource to read
    `inclueNewlines` - true when newlines should be included in the generated string, otherwise false
  Returns:
    a string containing the contents of the file

### refreshLocalWorkspaceFile

    public static boolean refreshLocalWorkspaceFile(org.eclipse.core.resources.IFile fileResource,
                                                    org.eclipse.core.runtime.IProgressMonitor progressMonitor)

  Refreshes the given file so it will be in synch with the local file system.

  Parameters:
    `fileResource` - the file to refresh
    `progressMonitor` - a progress monitor to use during the refresh
  Returns:
    `true` when the file was refreshed OK, otherwise `false`

### saveStatementAsSQLFileResource

    public static org.eclipse.core.resources.IFile saveStatementAsSQLFileResource(QueryStatement statement,
                                                                                  java.lang.String projectName)

  Saves the given SQL statement as a file resource in the given project.

  Parameters:
    `statement` - the SQL statement to save
    `projectName` - the name of the project into which the query is to be saved
  Returns:
    the file resource in which the statement was saved, or `null` if it wasn't saved sucessfully

### saveTextAsSQLFileResource

    public static org.eclipse.core.resources.IFile saveTextAsSQLFileResource(java.lang.String content,
                                                                             java.lang.String resourceName,
                                                                             java.lang.String projectName)

  Saves the given string as the content as a SQL file resource with the given name in the given project. The file will have the extension ".sql" by default.

  Parameters:
    `content` - the string to save
    `resourceName` - the name of the SQL resource (the file name)
    `projectName` - the project in which to save the statement
  Returns:
    the file resource in which the text was saved, or `null` if it wasn't saved sucessfully

### saveStringAsFileResource

    public static void saveStringAsFileResource(org.eclipse.core.resources.IFile fileResource,
                                                java.lang.String content)

  Saves the given string as the content of the given file resource.

  Parameters:
    `fileResource` - the file resource in which to save the string
    `content` - the string to save

### getSegments

    public static int[] getSegments(int offset,
                                    java.lang.String text)

  Searches a string and returns the segments containing qoutes '"'

  Parameters:
    `offset` - the line offset
    `text` - the string text to search
  Returns:
    an array of segments