org.formaria.editor.netbeans.project.pages
Class EditorUtility

java.lang.Object
  extended by org.formaria.editor.netbeans.project.pages.EditorUtility
All Implemented Interfaces:
IEditorUtility

public class EditorUtility
extends java.lang.Object
implements IEditorUtility

A utility class to help interact with the NetBeans editors

Copyright (c) Formaria Ltd., 1998-2004

License: see license.txt


Field Summary
 
Fields inherited from interface org.formaria.editor.project.pages.IEditorUtility
FRAME_HEIGHT, FRAME_WIDTH
 
Constructor Summary
EditorUtility()
           
 
Method Summary
 boolean activateEditor(PageResource pageRes, boolean activate)
          Activate the source code editor for this page
 void addJar(EditorProject currentProject, java.net.URL jarUrl)
          Add a jar reference to the project class path.
 boolean canImportDbTable(java.awt.datatransfer.DataFlavor transferFlavor)
          Indicates whether database table can be imported from a given data flavor
 void copy(java.io.InputStream is, java.io.OutputStream os)
           
 void copyToClipboard(java.lang.String text)
          Copies the given text to the internal netbeans clipboard
 Page getCachedPage(EditorProject currentProject, PageResource pageRes)
          If the page xml has been cached we want to use that xml to generate the page otherwise we just return the page contained in the pageRes object
 java.sql.Connection getDbConnection(java.lang.Object obj)
          Retrieve database connection from obj
 java.lang.String getDbConnectionName(java.lang.Object obj)
          Get database connection name
 java.lang.String getDbDriver(java.lang.Object obj)
          Get database driver name
 java.lang.String getDbDriverFile(java.lang.Object tableNode)
          Get the path to the file (zip, jar) containing the jdbc driver used to connect the the database.
 java.lang.String getDbPassword(java.lang.Object obj)
          Get database connection password
 java.lang.String getDbTableName(java.lang.Object obj)
          Get the table name
 java.lang.ClassLoader getEditorClassLoader(EditorProject project)
          Gets the class loader being used by the editor to load resources of the specified project.
 javax.swing.JEditorPane getEditorPane(java.awt.Container cont)
          Search the container for an instance of JEditorPane
 javax.swing.JEditorPane getEditorPane(java.lang.String fileName)
          Search the container for an instance of JEditorPane
 java.lang.Object[] getHandlerMethods(EditorProject currentProject, java.lang.String fileName)
          Get a list of the methods provided by the page class
 Modifiable getPageDataObject(EditorProject currentProject, java.lang.String name)
          Retrieve the PageDataObject for the page with the passed name
 java.lang.String getPlatform()
           
 java.net.URL[] getProjectURLs(EditorProject project)
          Gets the classpath URLs of the given project.
 boolean hasMethod(EditorProject currentProject, java.lang.String fileName, java.lang.String methodName)
          Check if a method is already contained within the direct superclass
 void insertTextAtCaret(java.lang.Object sce, java.lang.String newText)
           
 boolean isEclipse()
          Is this an eclipse plugin?
 boolean isValid(java.lang.Object sourceCodeEditor)
           
 java.awt.Image loadImage(java.lang.String name)
           
 boolean locateMethod(Project currentProject, PageResource pageRes, java.lang.Object sce, java.lang.String methodName, java.lang.String searchText, boolean addNew, boolean ctrlDown)
           
 void markDirty(EditorProject project)
          Mark the project as dirty
 boolean openSourceFile(EditorProject currentProject, PageResource pageResource, java.lang.String fileName)
           
 void requestActive(java.lang.Object sourceEditor)
           
protected  java.lang.String retrieveDriverFile(java.lang.String driverName, java.lang.Object driverListNodeChildren)
          Tries to retrievs the name of the file that contains the specified driver
 boolean setSourceCodeEditor(PageResource pageRes, java.lang.String fileName)
          Set the source code editor for the pageResource
 void showErrorMessage(java.lang.String msg, java.lang.String title)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EditorUtility

public EditorUtility()
Method Detail

getDbConnection

public java.sql.Connection getDbConnection(java.lang.Object obj)
Retrieve database connection from obj

Specified by:
getDbConnection in interface IEditorUtility
Parameters:
obj - the object from which the database connection is to be obtained
Returns:
the database connection

getDbDriverFile

public java.lang.String getDbDriverFile(java.lang.Object tableNode)
Get the path to the file (zip, jar) containing the jdbc driver used to connect the the database. This method is fragile, it works with nb5.5 but can break in the next version.

Specified by:
getDbDriverFile in interface IEditorUtility
Parameters:
tableNode - the table node object from which the db driver path will be otained.

retrieveDriverFile

protected java.lang.String retrieveDriverFile(java.lang.String driverName,
                                              java.lang.Object driverListNodeChildren)
                                       throws java.lang.Exception
Tries to retrievs the name of the file that contains the specified driver

Parameters:
driverName - the name of the driver
Throws:
java.lang.Exception

getDbConnectionName

public java.lang.String getDbConnectionName(java.lang.Object obj)
Get database connection name

Specified by:
getDbConnectionName in interface IEditorUtility
Parameters:
obj - the object from which the connection name is to be obtained
Returns:
the database connection name

getDbDriver

public java.lang.String getDbDriver(java.lang.Object obj)
Get database driver name

Specified by:
getDbDriver in interface IEditorUtility
Parameters:
obj - the object from which the driver name is to be obtained
Returns:
the driver name

getDbPassword

public java.lang.String getDbPassword(java.lang.Object obj)
Get database connection password

Specified by:
getDbPassword in interface IEditorUtility
Parameters:
obj - the object from which the password is to be obtained
Returns:
database connection password

getDbTableName

public java.lang.String getDbTableName(java.lang.Object obj)
Get the table name

Specified by:
getDbTableName in interface IEditorUtility
Parameters:
obj - the object from which the table name is to be obtained
Returns:
table name

canImportDbTable

public boolean canImportDbTable(java.awt.datatransfer.DataFlavor transferFlavor)
Indicates whether database table can be imported from a given data flavor

Specified by:
canImportDbTable in interface IEditorUtility
Parameters:
transferFlavors - the data formats available
Returns:
true if database table can be imported, false otherwise

setSourceCodeEditor

public boolean setSourceCodeEditor(PageResource pageRes,
                                   java.lang.String fileName)
Set the source code editor for the pageResource

Specified by:
setSourceCodeEditor in interface IEditorUtility

activateEditor

public boolean activateEditor(PageResource pageRes,
                              boolean activate)
Activate the source code editor for this page

Specified by:
activateEditor in interface IEditorUtility
Parameters:
pageRes - the page resource that owns the source
activate - force the source editor to display if true
Returns:
true if the editor is open and has been activated, otherwise false

getEditorPane

public javax.swing.JEditorPane getEditorPane(java.awt.Container cont)
Search the container for an instance of JEditorPane

Specified by:
getEditorPane in interface IEditorUtility
Parameters:
cont - the container to search
Returns:
the editor or null if none is found

getEditorPane

public javax.swing.JEditorPane getEditorPane(java.lang.String fileName)
Search the container for an instance of JEditorPane

Specified by:
getEditorPane in interface IEditorUtility
Parameters:
cont - the container to search
Returns:
the editor or null if none is found

getPageDataObject

public Modifiable getPageDataObject(EditorProject currentProject,
                                    java.lang.String name)
Retrieve the PageDataObject for the page with the passed name

Specified by:
getPageDataObject in interface IEditorUtility
Parameters:
name - the name of the page whose PageDataObject we wish to retrieve
Returns:
the PageDataObject

getProjectURLs

public java.net.URL[] getProjectURLs(EditorProject project)
Gets the classpath URLs of the given project.

Specified by:
getProjectURLs in interface IEditorUtility
Parameters:
project - project whose classpath entries will be returned
Returns:
table containing classpath URLs

getEditorClassLoader

public java.lang.ClassLoader getEditorClassLoader(EditorProject project)
Gets the class loader being used by the editor to load resources of the specified project.

Specified by:
getEditorClassLoader in interface IEditorUtility
Parameters:
project - project the classloader of which is to be obtained
Returns:
the ClassLoader object

getCachedPage

public Page getCachedPage(EditorProject currentProject,
                          PageResource pageRes)
If the page xml has been cached we want to use that xml to generate the page otherwise we just return the page contained in the pageRes object

Specified by:
getCachedPage in interface IEditorUtility
Parameters:
pageRes - the pageResource we're checking
Returns:
the newly parsed page or the page in the pageRes

requestActive

public void requestActive(java.lang.Object sourceEditor)
Specified by:
requestActive in interface IEditorUtility

locateMethod

public boolean locateMethod(Project currentProject,
                            PageResource pageRes,
                            java.lang.Object sce,
                            java.lang.String methodName,
                            java.lang.String searchText,
                            boolean addNew,
                            boolean ctrlDown)
Specified by:
locateMethod in interface IEditorUtility

insertTextAtCaret

public void insertTextAtCaret(java.lang.Object sce,
                              java.lang.String newText)
Specified by:
insertTextAtCaret in interface IEditorUtility

isValid

public boolean isValid(java.lang.Object sourceCodeEditor)
Specified by:
isValid in interface IEditorUtility

openSourceFile

public boolean openSourceFile(EditorProject currentProject,
                              PageResource pageResource,
                              java.lang.String fileName)
Specified by:
openSourceFile in interface IEditorUtility

hasMethod

public boolean hasMethod(EditorProject currentProject,
                         java.lang.String fileName,
                         java.lang.String methodName)
Check if a method is already contained within the direct superclass

Specified by:
hasMethod in interface IEditorUtility
Parameters:
currentProject - the current project
fileName - the full file name for the enclosing class
methodName - the bare method name e.g. 'showPrevious'

getHandlerMethods

public java.lang.Object[] getHandlerMethods(EditorProject currentProject,
                                            java.lang.String fileName)
Get a list of the methods provided by the page class

Specified by:
getHandlerMethods in interface IEditorUtility
Parameters:
currentProject - the current project
fileName - the full file name for the enclosing class

copy

public void copy(java.io.InputStream is,
                 java.io.OutputStream os)
Specified by:
copy in interface IEditorUtility

loadImage

public java.awt.Image loadImage(java.lang.String name)
Specified by:
loadImage in interface IEditorUtility

copyToClipboard

public void copyToClipboard(java.lang.String text)
Copies the given text to the internal netbeans clipboard

Specified by:
copyToClipboard in interface IEditorUtility
Parameters:
text - the text to be copied

getPlatform

public java.lang.String getPlatform()
Specified by:
getPlatform in interface IEditorUtility

showErrorMessage

public void showErrorMessage(java.lang.String msg,
                             java.lang.String title)
Specified by:
showErrorMessage in interface IEditorUtility

addJar

public void addJar(EditorProject currentProject,
                   java.net.URL jarUrl)
Add a jar reference to the project class path. Only add the jar if it is not already present

Specified by:
addJar in interface IEditorUtility
Parameters:
currentProject - the current project
jarUrl - the jar to add

isEclipse

public boolean isEclipse()
Is this an eclipse plugin?

Specified by:
isEclipse in interface IEditorUtility
Returns:
true if the plugin is designed to run on eclipse

markDirty

public void markDirty(EditorProject project)
Mark the project as dirty

Specified by:
markDirty in interface IEditorUtility
Parameters:
project - the current project