Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.6.0)

E13403-07

oracle.ide
Class Context

java.lang.Object
  extended by oracle.ide.Context

public final class Context
extends java.lang.Object

The Context interface provides information about the current IDE state. From this interface, Wizards and other classes receiving IDE actions can determine the active Project and Workspace as well as the currently selected Element.


Field Summary
static java.lang.String DATA_KEY
          Deprecated. since 11.1.1 use TraversableContext.find( Context.class ).
 
Constructor Summary
Context()
          Default constructor.
Context(Context originalContext)
          Copy constructor.
Context(Element element)
          Constructor.
Context(Node node)
          Constructor.
Context(View view, Workspace workspace, Project project, Node node)
          Constructor.
Context(Workspace workspace, Project project)
          Constructor.
 
Method Summary
 boolean containsProperty(java.lang.String name)
          Returns true if the specified property is currently contained in this Context; false otherwise.
 boolean equals(java.lang.Object o)
          Compares the Context to another object for equality.
 boolean getBoolean(java.lang.String name)
          Convenience method for getting a boolean property from the Context.
 Element getElement()
          Convenience method for returning the first item from getSelection().
 java.util.EventObject getEvent()
          Provides a reference to the EventObject associated with this Context.
 int getInt(java.lang.String name)
          Convenience method for getting an int property from the Context.
 Node getNode()
          Gets the Node that owns the selection.
 Project getProject()
          Provides a reference to the Project data associated with this Context.
 java.lang.Object getProperty(java.lang.String name)
          Gets a property associated with this Context.
 Element[] getSelection()
          Gets the list of selected Elements.
 View getView()
          Provides a reference to the View associated with this Context.
 Workspace getWorkspace()
          Provides a reference to the Workspace associated with this Context.
 int hashCode()
          This implementation exists solely to enforce the contract for Object.hashCode().
static Context newIdeContext()
          Returns a Context initialized with the active Workspace, its active Project, the MainWindow's last active View, and the selection of Element held by that View.
static Context newIdeContext(Element element)
          Returns a Context initialized with the active Workspace, its active Project, the main window's last active View, and the specified Element as the selection.
static Context newIdeContext(Node node)
          Returns a Context initialized with the active Workspace, its active Project, the main window's last active View, and the specified Node as the node, element, and selection.
static Context newIdeContext(View view)
          Returns a Context initialized with the active Workspace, its active Project, the specified View, and the selection of the specified View.
static Context newIdeContext(View view, java.util.EventObject event)
          Calls #newIdeContext(oracle.ide.addin.View), sets the specified EventObject as the event, and returns the resulting Context.
 void removeProperty(java.lang.String name)
          Removes a property set on this Context.
 void setBoolean(java.lang.String name, boolean value)
          Convenience method for setting a boolean property in the Context.
 void setElement(Element element)
          Convenience method for setting the selection to be the specified Element.
 void setEvent(java.util.EventObject event)
          Set the EventObject to be associated with this Context.
 void setInt(java.lang.String name, int value)
          Convenience method for setting an int property in the Context.
 void setNode(Node node)
          Sets the Node that owns the selection.
 void setProject(Project project)
          Set a reference to the Project data associated with this Context.
 void setProperty(java.lang.String name, java.lang.Object value)
          Sets a property on this Context.
 void setSelection(Element[] selection)
          Sets the list of selected Elements.
 void setView(View view)
          Set a reference to the View to be associated with this Context.
 void setWorkspace(Workspace workspace)
          Sets a reference to the Workspace to be associated with this Context.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DATA_KEY

public static final java.lang.String DATA_KEY
Deprecated. since 11.1.1 use TraversableContext.find( Context.class ).
Use DATA_KEY to retrieve the Context from a TraversableContext.

Constructor Detail

Context

public Context()
Default constructor.


Context

public Context(Context originalContext)
Copy constructor. Peforms a shallow copy of the given Context. If the context passed in is null, the new Context will be empty. Caller is responsible for initializing the newly created context.


Context

public Context(Element element)
Constructor.

Parameters:
element - the Element associated with this context.

Context

public Context(Node node)
Constructor.

Parameters:
node - the Node associated with this context.

Context

public Context(Workspace workspace,
               Project project)
Constructor.

Parameters:
workspace - the workspace associated with this context.
project - the project associated with this context.

Context

public Context(View view,
               Workspace workspace,
               Project project,
               Node node)
Constructor.

Parameters:
view - the View associated with this context.
workspace - the Workspace associated with this context.
project - the Project associated with this context.
node - the Node associated with this context.
Method Detail

newIdeContext

public static Context newIdeContext()
Returns a Context initialized with the active Workspace, its active Project, the MainWindow's last active View, and the selection of Element held by that View.


newIdeContext

public static Context newIdeContext(Element element)
Returns a Context initialized with the active Workspace, its active Project, the main window's last active View, and the specified Element as the selection.


newIdeContext

public static Context newIdeContext(Node node)
Returns a Context initialized with the active Workspace, its active Project, the main window's last active View, and the specified Node as the node, element, and selection.


newIdeContext

public static Context newIdeContext(View view)
Returns a Context initialized with the active Workspace, its active Project, the specified View, and the selection of the specified View.


newIdeContext

public static Context newIdeContext(View view,
                                    java.util.EventObject event)
Calls #newIdeContext(oracle.ide.addin.View), sets the specified EventObject as the event, and returns the resulting Context.


equals

public final boolean equals(java.lang.Object o)
Compares the Context to another object for equality.

Overrides:
equals in class java.lang.Object

hashCode

public final int hashCode()
This implementation exists solely to enforce the contract for Object.hashCode(). A Context should never be used as a hash key.

Overrides:
hashCode in class java.lang.Object

getProperty

public final java.lang.Object getProperty(java.lang.String name)
Gets a property associated with this Context.

All properties associated with a Context are transient, meaning they are only available during the lifecycle the particular Context object. Context objects tend to be short-lived, lasting only while an action is being performed or while menus and toolbars are being updated. The IDE will not preserve properties set on the current Context when creating a new Context.

Context properties are intended to be a simple mechanism for extensions to collaborate on a particular action or to optimize performance by allowing the storage of arbitrary temporary values in the Context.

A typical pattern is to encapsulate the lookup and typecast of a property in static utility methods, so that clients of a custom property have a typesafe way to get and set the property without having to know its String name in the Context. For example:

    private static final String XYZ = "myExtension.xyz";
    public static Xyz getXyz( Context context )
    {
      return (Xyz) context.getProperty( XYZ );
    }
    public static void setXyz( Context context, Xyz xyz )
    {
      context.setProperty( XYZ, xyz );
    }
  

Parameters:
name - The name of the property to retrieve from the Context.

setProperty

public final void setProperty(java.lang.String name,
                              java.lang.Object value)
Sets a property on this Context. The property will continue to be available until the IDE discards the Context. A null value is allowed, so to remove a property, use removeProperty(String).

All properties associated with a Context are transient, meaning they are only available during the lifecycle the particular Context object. Context objects tend to be short-lived, lasting only while an action is being performed or while menus and toolbars are being updated. The IDE will not preserve properties set on the current Context when creating a new Context.

Context properties are intended to be a simple mechanism for extensions to collaborate on a particular action or to optimize performance by allowing the storage of arbitrary temporary values in the Context.

A typical pattern is to encapsulate the lookup and typecast of a property in static utility methods, so that clients of a custom property have a typesafe way to get and set the property without having to know its String name in the Context. (It also improves the code fan-in metric.) For example:

    private static final String XYZ = "myExtension.xyz";
    public static Xyz getXyz( Context context )
    {
      return (Xyz) context.getProperty( XYZ );
    }
    public static void setXyz( Context context, Xyz xyz )
    {
      context.setProperty( XYZ, xyz );
    }
  

Parameters:
name - The name of the property to set on the Context.
value - The value of the property to set on the Context.

removeProperty

public final void removeProperty(java.lang.String name)
Removes a property set on this Context.


containsProperty

public final boolean containsProperty(java.lang.String name)
Returns true if the specified property is currently contained in this Context; false otherwise.


getBoolean

public final boolean getBoolean(java.lang.String name)
Convenience method for getting a boolean property from the Context.

Parameters:
name - The name of the property.
Returns:
The value of the property.

setBoolean

public final void setBoolean(java.lang.String name,
                             boolean value)
Convenience method for setting a boolean property in the Context.

Parameters:
name - The name of the property.
value - The value of the property.

getInt

public final int getInt(java.lang.String name)
Convenience method for getting an int property from the Context.

Parameters:
name - The name of the property.
Returns:
The value of the property.

setInt

public final void setInt(java.lang.String name,
                         int value)
Convenience method for setting an int property in the Context.

Parameters:
name - The name of the property.
value - The value of the property.

getView

public final View getView()
Provides a reference to the View associated with this Context.

Returns:
the associated View object.

setView

public final void setView(View view)
Set a reference to the View to be associated with this Context.


getWorkspace

public final Workspace getWorkspace()
Provides a reference to the Workspace associated with this Context.


setWorkspace

public final void setWorkspace(Workspace workspace)
Sets a reference to the Workspace to be associated with this Context.


getProject

public final Project getProject()
Provides a reference to the Project data associated with this Context.


setProject

public final void setProject(Project project)
Set a reference to the Project data associated with this Context.


getEvent

public final java.util.EventObject getEvent()
Provides a reference to the EventObject associated with this Context.

Returns:
the EventObject associated with this Context.
See Also:
setEvent(java.util.EventObject)

setEvent

public final void setEvent(java.util.EventObject event)
Set the EventObject to be associated with this Context.

Parameters:
event - the EventObject to associate with this Context.
See Also:
getEvent()

getSelection

public final Element[] getSelection()
Gets the list of selected Elements.

The selection must either be all Subjecs, else all not Subjects. That is to say, all the Elements in the selection will also be Subjects, else none of them will.

In the case where none of the selected Elements are Subjects, the getDefaultSubject method will return the Subject to which the selected Elements apply.
The primary purpose of this restrciction is to allow the Inspector to know what object(s) to use when sending update notification messages.

Returns:
a non-null array of selected Elements.

setSelection

public final void setSelection(Element[] selection)
Sets the list of selected Elements. The selection must either be all Subjecs, else all not Subjects. That is to say, all the Elements in the selection will also be Subjects, else none of them will. In the case where none of the selected Elements are Subjects, the getDefaultSubject method will return the Subject to which the selected Elements apply. The primary purpose of this restrciction is to allow the Inspector to know what object(s) to use when sending update notification messages.


getNode

public final Node getNode()
Gets the Node that owns the selection. If the selection contains multiple Nodes, this methods returns the first Node.

Returns:
the Node that owns the selection.

setNode

public final void setNode(Node node)
Sets the Node that owns the selection.


getElement

public final Element getElement()
Convenience method for returning the first item from getSelection().

Returns:
the first Element in the selection
See Also:
getSelection()

setElement

public final void setElement(Element element)
Convenience method for setting the selection to be the specified Element.

Parameters:
element - The new selection.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.6.0)

E13403-07

Copyright © 1997, 2011, Oracle. All rights reserved.