uk.ac.kcl.cch.jb.pliny
Class PlinyPlugin

java.lang.Object
  extended byorg.eclipse.core.runtime.Plugin
      extended byorg.eclipse.ui.plugin.AbstractUIPlugin
          extended byuk.ac.kcl.cch.jb.pliny.PlinyPlugin
All Implemented Interfaces:
org.osgi.framework.BundleActivator

public class PlinyPlugin
extends org.eclipse.ui.plugin.AbstractUIPlugin

The main plugin class for Pliny to be used in the desktop. The plugin as a whole is a classic Eclipse plugin, and contains many basic Pliny elements including most of the model and UI code.

This plugin class itself, as well as supporting the usual base Eclipse functionality provides several Pliny-specific functions:

Author:
John Bradley

Field Summary
 
Fields inherited from class org.eclipse.core.runtime.Plugin
PLUGIN_PREFERENCE_SCOPE, PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME, PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME
 
Constructor Summary
PlinyPlugin()
          The constructor.
 
Method Summary
 boolean cacheImage(URL url, int imageNo)
          fetches and stores the image associated with the URL in the image cache managed by this plugin.
static void clearStreamBuffer()
           
static void copyInputStream(InputStream in, OutputStream out)
          a utility function to copy material in input stream to the output stream.
static org.eclipse.swt.graphics.Color getColour(String name, org.eclipse.swt.graphics.RGB rgb)
          uses the parameter as a key to the colour registry.
 Connection getConnection()
          returns a DB connection to the Pliny backing database.
static BaseObject getCurrentObject()
           
static DBServices getDBServicesInstance()
          Returns the shared instance of DBServices -- the access mechanism for Pliny's backing database.
static PlinyPlugin getDefault()
          Returns the shared instance.
 org.eclipse.jface.resource.ImageDescriptor getFromImageCache(URL url, int imageNo)
          returns an ImageDescriptor that points to an image in the cache.
 org.eclipse.swt.graphics.Image getImage(String id)
          Returns an image from the image registry based on a given string as a key.
 File getImageCachePath()
          returns a File that represents the directory where the Pliny image cache is located.
static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(String path)
          Returns an image descriptor for the image file at the given plug-in relative path.
 Set getOpenNotesIds()
          returns the set of Pliny open note editors.
static int getReferenceNumber()
          returns the current reference number associated with the referent.
static Resource getReferent()
          gets the current referent.
static IResourceExtensionProcessor getResourceExtensionProcessor(int otKey)
          returns a ResourceExtensionProcessor associated with the given DB key for an ObjectType.
static IResourceExtensionProcessor getResourceExtensionProcessor(ObjectType type)
          returns a ResourceExtensionProcessor associated with the given ObjectType.
static IResourceExtensionProcessor getResourceExtensionProcessor(Resource resource)
          returns a ResourceExtensionProcessor associated with the given Resource through that Resource's ObjectType.
 String getStateLocationUrl(String objectName)
          returns a path to the plugin's state area that is extended by the given name.
static int incReferenceNumber()
          increments and returns the current reference number associated with the referent.
 void returnConnection(Connection c)
          returns the given connection (got with getConnection() back.
static void setCurrentObject(BaseObject obj)
           
static void setReferent(Resource resource)
          stores the given Resource to be the new Referent.
 void start(org.osgi.framework.BundleContext context)
          This method is called upon plug-in activation
 void stop(org.osgi.framework.BundleContext context)
          This method is called when the plug-in is stopped
static void updateColour(String name, org.eclipse.swt.graphics.RGB rgb)
          updates the colour associated with the given name to be the new colour.
 
Methods inherited from class org.eclipse.ui.plugin.AbstractUIPlugin
createImageRegistry, getDialogSettings, getImageRegistry, getPreferenceStore, getWorkbench, imageDescriptorFromPlugin, initializeDefaultPluginPreferences, initializeDefaultPreferences, initializeImageRegistry, loadDialogSettings, loadPreferenceStore, refreshPluginActions, saveDialogSettings, savePreferenceStore, shutdown, startup
 
Methods inherited from class org.eclipse.core.runtime.Plugin
find, find, getBundle, getDescriptor, getLog, getPluginPreferences, getStateLocation, internalInitializeDefaultPluginPreferences, isDebugging, openStream, openStream, savePluginPreferences, setDebugging, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PlinyPlugin

public PlinyPlugin()
The constructor.

Method Detail

start

public void start(org.osgi.framework.BundleContext context)
           throws Exception
This method is called upon plug-in activation

Throws:
Exception

stop

public void stop(org.osgi.framework.BundleContext context)
          throws Exception
This method is called when the plug-in is stopped

Throws:
Exception

getDefault

public static PlinyPlugin getDefault()
Returns the shared instance.


getDBServicesInstance

public static DBServices getDBServicesInstance()
Returns the shared instance of DBServices -- the access mechanism for Pliny's backing database.


getImageDescriptor

public static org.eclipse.jface.resource.ImageDescriptor getImageDescriptor(String path)
Returns an image descriptor for the image file at the given plug-in relative path.

Parameters:
path - the path
Returns:
the image descriptor

getImage

public org.eclipse.swt.graphics.Image getImage(String id)
Returns an image from the image registry based on a given string as a key.

Parameters:
id - the key by which the image is identified in the registry
Returns:
the image

getStateLocationUrl

public String getStateLocationUrl(String objectName)
returns a path to the plugin's state area that is extended by the given name. This is a convenience method.

Parameters:
objectName - name to be added to the state area path
Returns:
the extended path

getConnection

public Connection getConnection()
returns a DB connection to the Pliny backing database.

Returns:
a DB connection

returnConnection

public void returnConnection(Connection c)
returns the given connection (got with getConnection() back. This allows for connection pooling, although this is not currently used in Pliny -- there is only one connection made available.

Parameters:
c - the connection to return

getImageCachePath

public File getImageCachePath()
returns a File that represents the directory where the Pliny image cache is located.

Returns:
a File as a directory

cacheImage

public boolean cacheImage(URL url,
                          int imageNo)
fetches and stores the image associated with the URL in the image cache managed by this plugin. The key to the image will be the given image number.

Parameters:
url - a URL to the image to be cached.
imageNo - the key to be used to store the image
Returns:
returns false if the process failed -- IO error or file not found, etc.

getFromImageCache

public org.eclipse.jface.resource.ImageDescriptor getFromImageCache(URL url,
                                                                    int imageNo)
returns an ImageDescriptor that points to an image in the cache. The URL is used to provide a suitable file extension (for image type info).

Parameters:
url - URL to the image
imageNo - key number in cache for the image.
Returns:
ImageDescriptor for the image

getOpenNotesIds

public Set getOpenNotesIds()
returns the set of Pliny open note editors. Notes with open editors are identified as a set of Integers containing DB keys to the note.

Returns:
a Set of Integers -- keys to note objects in the DB.

getColour

public static org.eclipse.swt.graphics.Color getColour(String name,
                                                       org.eclipse.swt.graphics.RGB rgb)
uses the parameter as a key to the colour registry. If the entry is there, returns it as a Color object. If it is not there, it stores the given RDB object in the registry so that it will be there next time.

The returned Color object is managed by the registry and need not be disposed by the caller.

Parameters:
name - name as key to the colour
rgb - colour to be used if not in registry
Returns:
Color object that represents the colour.

updateColour

public static void updateColour(String name,
                                org.eclipse.swt.graphics.RGB rgb)
updates the colour associated with the given name to be the new colour.

Parameters:
name - name of registry entry to be updated.
rgb - RGB of new colour to be stored

getResourceExtensionProcessor

public static IResourceExtensionProcessor getResourceExtensionProcessor(int otKey)
returns a ResourceExtensionProcessor associated with the given DB key for an ObjectType. The value might be null if there is no associated processor.

Parameters:
otKey - DB key of the ObjectType
Returns:
IResourceExtensionProcessor the matching processor

getResourceExtensionProcessor

public static IResourceExtensionProcessor getResourceExtensionProcessor(ObjectType type)
returns a ResourceExtensionProcessor associated with the given ObjectType. The value might be null if there is no associated processor.

Parameters:
type -
Returns:
IResourceExtensionProcessor the matching processor

getResourceExtensionProcessor

public static IResourceExtensionProcessor getResourceExtensionProcessor(Resource resource)
returns a ResourceExtensionProcessor associated with the given Resource through that Resource's ObjectType. The value might be null if there is no associated processor.

Parameters:
resource - the Resource in question
Returns:
IResourceExtensionProcessor the matching processor

setReferent

public static void setReferent(Resource resource)
stores the given Resource to be the new Referent. Pass in null to clear the current referent.

Parameters:
resource - the new object to be the referent

getReferent

public static Resource getReferent()
gets the current referent. This will return null if there is no current referent.

Returns:
Resource

incReferenceNumber

public static int incReferenceNumber()
increments and returns the current reference number associated with the referent.

Returns:
int representing the current reference number

getReferenceNumber

public static int getReferenceNumber()
returns the current reference number associated with the referent.

Returns:
int representing the current reference number

setCurrentObject

public static void setCurrentObject(BaseObject obj)

getCurrentObject

public static BaseObject getCurrentObject()

copyInputStream

public static final void copyInputStream(InputStream in,
                                         OutputStream out)
                                  throws IOException
a utility function to copy material in input stream to the output stream. Streams are closed after copy.

Parameters:
in - Input Stream
out - Output Stream
Throws:
IOException

clearStreamBuffer

public static final void clearStreamBuffer()