Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 


Eclipse Platform
Release 3.5

org.eclipse.jface.resource
Class LocalResourceManager

java.lang.Object
  extended by 

org.eclipse.jface.resource.ResourceManager
      extended by 
org.eclipse.jface.resource.LocalResourceManager

public final class LocalResourceManager
extends ResourceManager

A local registry that shares its resources with some global registry. LocalResourceManager is typically used to safeguard against leaks. Clients can use a nested registry to allocate and deallocate resources in the global registry. Calling dispose() on the nested registry will deallocate everything allocated for the nested registry without affecting the rest of the global registry.

A nested registry can be used to manage the resources for, say, a dialog box.

Since:
3.1

Constructor Summary
LocalResourceManager ( ResourceManager parentRegistry)
          Creates a local registry that delegates to the given global registry for all resource allocation and deallocation.
LocalResourceManager ( ResourceManager parentRegistry, Control owner)
          Creates a local registry that wraps the given global registry.
 
Method Summary
protected   Object allocate ( DeviceResourceDescriptor descriptor)
          Called the first time a resource is requested.
  Object create ( DeviceResourceDescriptor descriptor)
          Returns the resource described by the given descriptor.
protected  void deallocate ( Object resource, DeviceResourceDescriptor descriptor)
          Called the last time a resource is dereferenced.
 void destroy ( DeviceResourceDescriptor descriptor)
          Deallocates a resource previously allocated by ResourceManager.create(DeviceResourceDescriptor).
 void dispose ()
          Deallocates any resources allocated by this registry that have not yet been deallocated.
  Object find ( DeviceResourceDescriptor descriptor)
          Returns a previously allocated resource associated with the given descriptor, or null if none exists yet.
protected   Image getDefaultImage ()
          Returns the default image that will be returned in the event that the intended image is missing.
  Device getDevice ()
          Returns the Device for which this ResourceManager will create resources
 
Methods inherited from class org.eclipse.jface.resource. ResourceManager
cancelDisposeExec, createColor, createColor, createFont, createImage, createImageWithDefault, destroyColor, destroyColor, destroyFont, destroyImage, disposeExec, get
 
Methods inherited from class java.lang. Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalResourceManager

public LocalResourceManager(
ResourceManager parentRegistry)
Creates a local registry that delegates to the given global registry for all resource allocation and deallocation.

Parameters:
parentRegistry - global registry

LocalResourceManager

public LocalResourceManager(
ResourceManager parentRegistry,
                            
Control owner)
Creates a local registry that wraps the given global registry. Anything allocated by this registry will be automatically cleaned up with the given control is disposed. Note that registries created in this way should not be used to allocate any resource that must outlive the given control.

Parameters:
parentRegistry - global registry that handles resource allocation
owner - control whose disposal will trigger cleanup of everything in the registry.
Method Detail

getDevice

public 
Device getDevice()
Description copied from class: ResourceManager
Returns the Device for which this ResourceManager will create resources

Specified by:
getDevice in class ResourceManager
Returns:
the Device associated with this ResourceManager

allocate

protected 
Object allocate(
DeviceResourceDescriptor descriptor)
                   throws 
DeviceResourceException
Called the first time a resource is requested. Should allocate and return a resource of the correct type.

Parameters:
descriptor - identifier for the resource to allocate
Returns:
the newly allocated resource
Throws:
DeviceResourceException - Thrown when allocation of an SWT device resource fails

deallocate

protected void deallocate(
Object resource,
                          
DeviceResourceDescriptor descriptor)
Called the last time a resource is dereferenced. Should release any resources reserved by allocate(...).

Parameters:
resource - resource being deallocated
descriptor - identifier for the resource

getDefaultImage

protected 
Image getDefaultImage()
Description copied from class: ResourceManager
Returns the default image that will be returned in the event that the intended image is missing.

Specified by:
getDefaultImage in class ResourceManager
Returns:
a default image that will be returned in the event that the intended image is missing.

create

public final 
Object create(
DeviceResourceDescriptor descriptor)
                    throws 
DeviceResourceException
Description copied from class: ResourceManager
Returns the resource described by the given descriptor. If the resource already exists, the reference count is incremented and the exiting resource is returned. Otherwise, a new resource is allocated. Every call to this method should have a corresponding call to ResourceManager.destroy(DeviceResourceDescriptor).

If the resource is intended to live for entire lifetime of the resource manager, a subsequent call to ResourceManager.destroy(DeviceResourceDescriptor) may be omitted and the resource will be cleaned up when the resource manager is disposed. This pattern is useful for short-lived LocalResourceManagers, but should never be used with the global resource manager since doing so effectively leaks the resource.

The resources returned from this method are reference counted and may be shared internally with other resource managers. They should never be disposed outside of the ResourceManager framework, or it will cause exceptions in other code that shares them. For example, never call Resource.dispose() on anything returned from this method.

Callers may safely downcast the result to the resource type associated with the descriptor. For example, when given an ImageDescriptor, the return value of this method will always be an Image.

Specified by:
create in class ResourceManager
Parameters:
descriptor - descriptor for the resource to allocate
Returns:
the newly allocated resource (not null)
Throws:
DeviceResourceException - if unable to allocate the resource

destroy

public final void destroy(
DeviceResourceDescriptor descriptor)
Description copied from class: ResourceManager
Deallocates a resource previously allocated by ResourceManager.create(DeviceResourceDescriptor). Descriptors are compared by equality, not identity. If the same resource was created multiple times, this may decrement a reference count rather than disposing the actual resource.

Specified by:
destroy in class ResourceManager
Parameters:
descriptor - identifier for the resource

dispose

public void dispose()
Deallocates any resources allocated by this registry that have not yet been deallocated.

Overrides:
dispose in class ResourceManager
Since:
3.1

find

public 
Object find(
DeviceResourceDescriptor descriptor)
Description copied from class: ResourceManager
Returns a previously allocated resource associated with the given descriptor, or null if none exists yet.

Specified by:
find in class ResourceManager
Parameters:
descriptor - descriptor to find
Returns:
a previously allocated resource for the given descriptor or null if none.

Eclipse Platform
Release 3.5

Guidelines for using Eclipse APIs.

Copyright (c) Eclipse contributors and others 2000, 2008. All rights reserved.


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire