Class DomainObjectListenerBuilder
DomainObjectListener
for
DomainObjectChangedEvent
s
There are three basic ways to process DomainObjectChangeRecord
s within a
DomainObjectChangedEvent
.
The first way is to look for the event to contain one or more
records of a certain type, and if it is there, do some major refresh operation, and ignore
the remaining event records. This is can be handled with an AbstractDomainObjectListenerBuilder.any(EventType...)
,
followed by a AbstractDomainObjectListenerBuilder.AnyBuilder.terminate(Callback)
or AbstractDomainObjectListenerBuilder.AnyBuilder.terminate(Consumer)
if you want the event.
new DomainObjectListenerBuilder() .any(DomainObjectEvent.RESTORED).call(() -> refreshAll()) .build();or if you need the event, you can use a consumer
new DomainObjectListenerBuilder() .any(DomainObjectEvent.RESTORED).call(e -> refreshAll(e)) .build();
The second way is to just test for presence of one or more records of a certain type, and if
any of those types exist is the event, call a method. In this case you don't need to know the
details of the record, only that one of the given events was fired. This can be handled using
the AbstractDomainObjectListenerBuilder.any(EventType...)
, followed by a call to AbstractDomainObjectListenerBuilder.AnyBuilder.call(Callback)
or
AbstractDomainObjectListenerBuilder.AnyBuilder.call(Consumer)
new DomainObjectListenerBuilder() .onAny(ProgramEvent.FUNCTION_CHANGED).call(() -> refreshFunctions()) .build();or if you need the event, you can use a consumer
new DomainObjectListenerBuilder() .onAny(ProgramEvent.FUNCTION_CHANGED).call(e -> refreshFunctions(e)) .build();
And finally, the third way is where you have to perform some processing on each record of a
certain type. This can be done using the the AbstractDomainObjectListenerBuilder.each(EventType...)
, followed by the
AbstractDomainObjectListenerBuilder.EachBuilder.call(Consumer)
if you just want the record, or
AbstractDomainObjectListenerBuilder.EachBuilder.call(BiConsumer)
if you want the record and the event.
By default, the consumer for the "each" case is typed on DomainObjectChangeRecord. But that
can be changed by calling AbstractDomainObjectListenerBuilder.with(Class)
. Once this is called the builder
will require that all consumers being passed in will now be typed on that record
class.
new DomainObjectListenerBuilder() .each(DomainObjectEvent.PROPERTY_CHANGED).call(r -> processPropertyChanged(r)) .withRecord(ProgramChangeRecord.class) .each(ProgramEvent.SYMBOL_RENANED).call(r -> symbolRenamed(r) .build(); private void processPropertyChanged(DomainObjectChangeRecord record) { ... } private void symbolRenamed(ProgramChangeRecord record) { ... }or if you also need the event (to get the domainObject that is the event source)
new DomainObjectListenerBuilder() .each(DomainObjectEvent.PROPERTY_CHANGED).call((e, r) -> processPropertyChanged(e, r)) .withRecord(ProgramChangeRecord.class) .each(ProgramEvent.SYMBOL_RENANED).call((e, r) -> symbolRenamed(e, r) .build(); private void propertyChanged(DomainObjectChangedEvent e, DomainObjectChangeRecord record) { Program p = (Program)e.getSource(). ... } private void symbolRenamed(DomainObjectChangedEvent e, ProgramChangeRecord record) { Program p = (Program)e.getSource(). ... }
-
Nested Class Summary
Nested classes/interfaces inherited from class ghidra.framework.model.AbstractDomainObjectListenerBuilder
AbstractDomainObjectListenerBuilder.AnyBuilder, AbstractDomainObjectListenerBuilder.EachBuilder
-
Constructor Summary
-
Method Summary
Methods inherited from class ghidra.framework.model.AbstractDomainObjectListenerBuilder
any, build, each, getName, ignoreWhen, with
-
Constructor Details
-
DomainObjectListenerBuilder
Constructs a new builder- Parameters:
creator
- the object that created this builder (usually, just pass in "this"). This will help with debugging event processing
-
-
Method Details
-
self
- Specified by:
self
in classAbstractDomainObjectListenerBuilder<DomainObjectChangeRecord,
DomainObjectListenerBuilder>
-