public class EventDefinition
extends java.lang.Object
implements java.io.Externalizable
Multiple events can be associated with multiple widgets. Any combination of a single event with a single widget is a valid exit condition or a trigger.
If there is no widgets specified, the case corresponds to the ANYWHERE option specified globally. Besides, a specific ANYWHERE option that accompanies the set of widgets can be specified.
If the association defines a trigger, the trigger ID should be a valid trigger ID from the trigger registry on the server. A special value of -1 means there is no trigger registered with this even definition instance, and, therefore, it defines the WAIT-FOR exit conditions.
A single instance of this class represents one association of a group of events with a group of widgets and/or the ANYWHERE option. To define a full list of triggers or exit conditions for a I/O statement, more than one instance may be necessary.
Widgets are specified with their numeric IDs. Events are specified with their symbolic names. These measures make this class independent from the server's classes and easily serializable.
The targets' IDs will be split in two sets, depending on the resource type:
The main reason for this approach is that widgets on P2J client-side have their own unique IDs which are computed different from their associated resource ID on server-side. Thus, mixing client-side widget IDs and resource IDs would not allow to differentiate which is which and it cascades in lot of changes in the UI client code. Also, for the same reason, a widget referenced via a handle in a i.e. "wait-for close of h" statement will register it in the set of widget IDs, and not resources. The other reason was that P2J uses a stack of UI event-queues which is empty when no wait-for loop is running; thus, server-events can not be posted there because they will get discarded if the event-queue is "trashed".Modifier and Type | Field and Description |
---|---|
private boolean |
anywhere
Specific ANYWHERE option, if given.
|
private java.util.Set<java.lang.String> |
events
Set of event names.
|
private java.util.Set<java.lang.Long> |
resources
Set of non-widget (or not-attached widget) resource IDs or null if anywhere globally.
|
private int |
triggerId
Trigger assigned to the event definition or -1 if exit condition.
|
private java.util.Set<java.lang.Integer> |
widgets
Set of widget IDs or null if anywhere globally.
|
Constructor and Description |
---|
EventDefinition()
Default constructor.
|
EventDefinition(boolean anywhere,
java.lang.Integer widgetId,
java.lang.String event)
Create a new event definition for the specified widget and event.
|
EventDefinition(boolean anywhere,
java.lang.Long resId,
java.lang.String event)
Create a new event definition for the specified resource and event.
|
EventDefinition(java.util.Set<java.lang.String> events,
java.util.Set<java.lang.Integer> widgets,
java.util.Set<java.lang.Long> resources,
boolean anywhere)
A constructor.
|
EventDefinition(java.lang.String event)
Create a new global ANYWHERE event definition for the specified event.
|
Modifier and Type | Method and Description |
---|---|
boolean |
anyEventForWidget(int widgetId)
Checks whether this definition contains exit conditions referring
to the specified widget.
|
java.util.LinkedList<EventDefinition> |
difference(EventDefinition ed)
Returns a list of 0 to 2 instances of
EventDefinition s which represent the
events, widgets and resources of this instance which are not in the specified one. |
(package private) java.util.Set<java.lang.String> |
getEvents()
Get the event list.
|
(package private) java.util.Set<java.lang.Long> |
getResourceIds()
Get the resource ids registered for this event.
|
java.util.Map<java.lang.Integer,java.lang.Integer> |
getRowDisplayEvents()
Search for registered ROW-DISPLAY events.
|
int |
getTriggerId()
Gets trigger ID of this event definition.
|
(package private) java.util.Set<java.lang.Integer> |
getWidgetIds()
Get the widget ids registered for this event.
|
EventDefinition |
intersection(EventDefinition ed)
Returns an instance of
EventDefinition which represents the common events,
widgets and resources with the specified one. |
boolean |
intersects(EventDefinition ed)
Checks whether this event definition has common events, widgets and resources with the
specified one.
|
boolean |
isAnywhere()
Gets widget or resource anywhere flag of this event definition.
|
boolean |
isAnywhereGlobally()
Check if this is a trigger for ANYWHERE globally.
|
static boolean |
isEventUniversal(int eventCode)
Classifies events as either universal or regular.
|
boolean |
isSame(EventDefinition other)
Reports if the given event definition is the same (in all data except for the trigger ID)
as the current instance.
|
int |
lookup(int frameId,
int widgetId,
java.lang.String event,
boolean isTrigger,
boolean specific,
boolean universal)
Checks whether this event matches any event defined in this
EventDefinition
instance. |
int |
lookup(long resourceId,
java.lang.String event,
boolean trigExit)
Checks whether this server event matches any server event defined in this
EventDefinition instance. |
void |
readExternal(java.io.ObjectInput in)
Replacement for the default object reading method.
|
void |
setTriggerId(int triggerId)
Sets trigger ID for this event definition making it a trigger event
definition.
|
void |
writeExternal(java.io.ObjectOutput out)
Replacement for the default object writing method.
|
private java.util.Set<java.lang.String> events
private java.util.Set<java.lang.Integer> widgets
private java.util.Set<java.lang.Long> resources
private boolean anywhere
private int triggerId
public EventDefinition()
public EventDefinition(java.util.Set<java.lang.String> events, java.util.Set<java.lang.Integer> widgets, java.util.Set<java.lang.Long> resources, boolean anywhere)
events
- a Set of event nameswidgets
- a Set of widget IDsresources
- a Set of non-widget resource IDsanywhere
- true
if these events are defined as ANYWHEREEventDefinition(boolean anywhere, java.lang.Integer widgetId, java.lang.String event)
anywhere
- State of the ANYWHERE option for ON ... event OF resource ANYWHERE.widgetId
- The widget ID.event
- The event name.EventDefinition(boolean anywhere, java.lang.Long resId, java.lang.String event)
anywhere
- State of the ANYWHERE option for ON ... event OF resource ANYWHERE.resId
- The resource ID.event
- The event name.EventDefinition(java.lang.String event)
event
- The event name.public static boolean isEventUniversal(int eventCode)
eventCode
- numeric event codetrue
if event is universal.public boolean isSame(EventDefinition other)
other
- The event definition to compare against.true
if the definitions are the same except the trigger ID.public boolean isAnywhere()
This does not track the global ANYWHERE event support. This is because global ANYWHERE
events are tracked in P2J without setting this flag, only when widgets
and
resources
are both null
. See isAnywhereGlobally()
.
TRUE
if the ANYWHERE option was specified with one or more widgets
or resources.public boolean isAnywhereGlobally()
public java.util.Map<java.lang.Integer,java.lang.Integer> getRowDisplayEvents()
public void setTriggerId(int triggerId)
triggerId
- ID of a trigger from the trigger registrypublic int getTriggerId()
-1
if this event definition
is for an exit condition.public int lookup(int frameId, int widgetId, java.lang.String event, boolean isTrigger, boolean specific, boolean universal)
EventDefinition
instance.frameId
- Frame ID, can be -1
.widgetId
- Widget ID to check or -1 if this is a global anywhere event.event
- The event name in the proper case (the caller should take care).isTrigger
- true
if the search is for a trigger or false
to
seach for an exit condition.specific
- true
if an exact match is to be returned.universal
- true
if the event is of the universal class.public int lookup(long resourceId, java.lang.String event, boolean trigExit)
EventDefinition
instance. Only exit conditions are checked.resourceId
- The ID of the resource.event
- event name in a proper case (the caller should take care)trigExit
- flag, telling the search is for a trigger (true
)
or for an exit condition (false
).public boolean anyEventForWidget(int widgetId)
widgetId
- widget ID to checktrue
if the widget is referred from herepublic boolean intersects(EventDefinition ed)
They intersect, if:
ed
- another instance of EventDefinition
true
if the event definitions have common events and widgetspublic EventDefinition intersection(EventDefinition ed)
EventDefinition
which represents the common events,
widgets and resources with the specified one.
The returned EventDefinition
retains all remaining internal fields of this one.
ed
- another instance of EventDefinition
EventDefinition
or null
if there is
nothing in common.public java.util.LinkedList<EventDefinition> difference(EventDefinition ed)
EventDefinition
s which represent the
events, widgets and resources of this instance which are not in the specified one.
The result list is empty if event, widget and resource lists match exactly.
If this is not the case, the result list contains 1 instance when widget lists match in both instances or don't exist, otherwise two.
More specifically, the resulting list is calculated as follows:
EventDefinition
is created off the DE, IW and IR
sets;
EventDefinition
is created off this events
(original set), and DW and DR sets if either DW or DR set is not empty
ed
- another instance of EventDefinition
EventDefinition
s or null
if there is nothing in common.public void readExternal(java.io.ObjectInput in) throws java.io.IOException, java.lang.ClassNotFoundException
readExternal
in interface java.io.Externalizable
in
- The input source from which fields will be restored.java.io.IOException
- In case of I/O errors.java.lang.ClassNotFoundException
- If payload can't be instantiated.public void writeExternal(java.io.ObjectOutput out) throws java.io.IOException
writeExternal
in interface java.io.Externalizable
out
- The output destination to which fields will be saved.java.io.IOException
- In case of I/O errors.java.util.Set<java.lang.Integer> getWidgetIds()
java.util.Set<java.lang.Long> getResourceIds()
java.util.Set<java.lang.String> getEvents()
events
.