Class ComponentModel
- java.lang.Object
-
- com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
-
- com.inductiveautomation.perspective.gateway.model.ComponentModel
-
- All Implemented Interfaces:
AuditingContext
,Component
,LoggingContext
,PerspectiveElement
,PropertyTreeOwner
- Direct Known Subclasses:
DesignerComponentModel
public class ComponentModel extends AbstractLifecycle implements Component
The model for a running client component, of which many may exist forming the complete component tree for a runningDesignerViewModel
;ComponentModels are created from the
ComponentConfig
s of a saved project.
-
-
Field Summary
Fields Modifier and Type Field Description protected com.inductiveautomation.perspective.gateway.model.ActionCollection
actions
protected int[]
addressPath
protected java.lang.String
addressPathString
protected BindingCollection
bindings
protected PropertyChangeScriptCollection
changeScripts
protected ComponentConfig
config
protected CustomMethodCollection
customMethods
protected com.inductiveautomation.perspective.gateway.model.ExtensionFunctionCollection
extensionFunctions
protected static LoggerEx
log
protected MessageHandlerCollection
messageHandlers
protected ComponentModel
parent
protected java.util.Map<PropertyType,PropertyTree>
properties
protected ViewModel
view
-
Fields inherited from interface com.inductiveautomation.perspective.gateway.api.Component
MDC_COMPONENT
-
-
Constructor Summary
Constructors Constructor Description ComponentModel(ViewModel view, ComponentConfig config, int[] addressPath, ComponentModel parent)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.util.List<ComponentModel>
children()
This method should always return a list containing all children, in the proper order.protected PropertyTreePermissionModel
createPermissionModel(PropertyType scope, PropertyConfigCollection config)
PropertyReference
createPropertyReference(java.lang.String referencePath, java.util.function.Consumer<PropertyTreeChangeEvent> subscriber, java.util.Set<Origin> acceptableOrigins)
Create aPropertyReference
with thisPerspectiveElement
as the target.void
dispatch(int[] propPath, int pointer, java.util.function.Consumer<ComponentModel> task)
Call that will walk down the component tree given a path of indices, and then execute a task on the component indicated by the path.java.util.Optional<PerspectiveElement>
findChildByName(java.util.Iterator<java.lang.String> pathIterator)
Attempts to locate a child at a given path.java.util.Optional<org.python.core.PyMethod>
findCustomMethod(java.lang.String methodName)
java.util.Optional<ExtensionFunction>
findExtensionFunction(java.lang.String name)
void
fireEvent(java.lang.String eventType, java.lang.String eventName, java.lang.Object eventObject)
Fire an event on component.void
focus()
AuditContext.Builder
getAuditSnapshot()
java.util.Optional<Component>
getChild(int childId)
java.util.Collection<Component>
getChildren()
java.lang.String
getComponentAddressPath()
Index path of the component, like "0:5"com.inductiveautomation.ignition.common.gson.JsonElement
getComponentState()
LoggerEx
getLogger()
LoggingContext
getMdcParent()
java.util.Optional<ComponentModelDelegate>
getModelDelegate()
java.lang.String
getName()
Component
getParent()
PropertyTree
getPropertyTreeOf(PropertyType type)
Fetch thePropertyTree
associated with the givenPropertyType
java.lang.String
getQualifiedPath()
java.lang.String
getTraceId()
ViewModel
getView()
protected void
initChildren(java.util.List<ComponentConfig> configChildren)
protected java.util.Map<PropertyType,PropertyTree>
initProperties()
void
mdcSetup()
Set up the MDC keys for this contextvoid
mdcTeardown()
Tear down the MDC keys that are added in #mdcSetupprotected com.inductiveautomation.perspective.gateway.model.ActionCollection
newActionHandler(EventConfig config)
protected void
onShutdown()
Shuts down bindings and then shuts down all childrenprotected void
onStartup()
Starts up the bindings and any childrenvoid
refreshBinding(PropertyKey property)
protected void
setName(java.lang.String name)
-
Methods inherited from class com.inductiveautomation.ignition.common.lifecycle.AbstractLifecycle
isRunning, shutdown, startup
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.inductiveautomation.perspective.gateway.api.AuditingContext
audit
-
Methods inherited from interface com.inductiveautomation.perspective.gateway.api.Component
getPage, getSession
-
Methods inherited from interface com.inductiveautomation.perspective.gateway.api.LoggingContext
mdc, mdcSetupTree, mdcTeardownTree, mdcWrap
-
Methods inherited from interface com.inductiveautomation.perspective.gateway.api.PerspectiveElement
getAuditProfile
-
-
-
-
Field Detail
-
log
protected static LoggerEx log
-
view
protected final ViewModel view
-
config
protected final ComponentConfig config
-
addressPath
protected final int[] addressPath
-
addressPathString
protected final java.lang.String addressPathString
-
properties
protected final java.util.Map<PropertyType,PropertyTree> properties
-
bindings
protected final BindingCollection bindings
-
changeScripts
protected final PropertyChangeScriptCollection changeScripts
-
actions
protected final com.inductiveautomation.perspective.gateway.model.ActionCollection actions
-
customMethods
protected final CustomMethodCollection customMethods
-
messageHandlers
protected final MessageHandlerCollection messageHandlers
-
extensionFunctions
protected final com.inductiveautomation.perspective.gateway.model.ExtensionFunctionCollection extensionFunctions
-
parent
protected final ComponentModel parent
-
-
Constructor Detail
-
ComponentModel
public ComponentModel(@Nonnull ViewModel view, @Nonnull ComponentConfig config, @Nonnull int[] addressPath, @Nullable ComponentModel parent)
-
-
Method Detail
-
newActionHandler
protected com.inductiveautomation.perspective.gateway.model.ActionCollection newActionHandler(EventConfig config)
-
initChildren
protected void initChildren(java.util.List<ComponentConfig> configChildren)
-
findExtensionFunction
public java.util.Optional<ExtensionFunction> findExtensionFunction(java.lang.String name)
- Specified by:
findExtensionFunction
in interfaceComponent
-
initProperties
protected java.util.Map<PropertyType,PropertyTree> initProperties()
-
createPermissionModel
protected PropertyTreePermissionModel createPermissionModel(PropertyType scope, PropertyConfigCollection config)
-
setName
protected void setName(java.lang.String name)
-
getName
public java.lang.String getName()
- Specified by:
getName
in interfacePerspectiveElement
- Returns:
- The name of the element. If this is a component, it will be the name of the component. If this is a View, the name will be "view". If this is a Page, the name will be "page". If this is the session, the name will be "session".
-
getQualifiedPath
public java.lang.String getQualifiedPath()
- Specified by:
getQualifiedPath
in interfacePerspectiveElement
- Returns:
- The qualified name of the element. If session or page, this is just the name. If a view or component, is the logical path starting at the view id.
-
findCustomMethod
public java.util.Optional<org.python.core.PyMethod> findCustomMethod(java.lang.String methodName)
-
getMdcParent
public LoggingContext getMdcParent()
- Specified by:
getMdcParent
in interfaceLoggingContext
-
mdcSetup
public void mdcSetup()
Description copied from interface:LoggingContext
Set up the MDC keys for this context- Specified by:
mdcSetup
in interfaceLoggingContext
-
mdcTeardown
public void mdcTeardown()
Description copied from interface:LoggingContext
Tear down the MDC keys that are added in #mdcSetup- Specified by:
mdcTeardown
in interfaceLoggingContext
-
onStartup
protected void onStartup()
Starts up the bindings and any children- Specified by:
onStartup
in classAbstractLifecycle
-
onShutdown
protected void onShutdown()
Shuts down bindings and then shuts down all children- Specified by:
onShutdown
in classAbstractLifecycle
-
getComponentAddressPath
public java.lang.String getComponentAddressPath()
Description copied from interface:Component
Index path of the component, like "0:5"- Specified by:
getComponentAddressPath
in interfaceComponent
-
getLogger
public LoggerEx getLogger()
- Specified by:
getLogger
in interfaceLoggingContext
-
getParent
@Nullable public Component getParent()
-
getModelDelegate
public java.util.Optional<ComponentModelDelegate> getModelDelegate()
-
refreshBinding
public void refreshBinding(PropertyKey property)
-
focus
public void focus()
-
dispatch
public void dispatch(int[] propPath, int pointer, java.util.function.Consumer<ComponentModel> task)
Call that will walk down the component tree given a path of indices, and then execute a task on the component indicated by the path.
-
children
@Nonnull protected java.util.List<ComponentModel> children()
This method should always return a list containing all children, in the proper order. Note that though all children are present and in the correct order, their index values may not be representative of their actual child ID (as is the case in the designer, where index and id diverge as changes are made to children).- Returns:
- a list of child component models, which may be empty but will never be null.
-
fireEvent
public void fireEvent(java.lang.String eventType, java.lang.String eventName, java.lang.Object eventObject)
Description copied from interface:Component
Fire an event on component. Can either be a 'component' event or a 'delegate' event.
-
getComponentState
public com.inductiveautomation.ignition.common.gson.JsonElement getComponentState()
-
getTraceId
public java.lang.String getTraceId()
- Returns:
- A string suitable for identifying this component in log messages. Will contain the address path, name, and component type, like "ia.display.label-MyLabel-0:5"
-
getPropertyTreeOf
@Nullable public PropertyTree getPropertyTreeOf(@Nullable PropertyType type)
Description copied from interface:PropertyTreeOwner
Fetch thePropertyTree
associated with the givenPropertyType
- Specified by:
getPropertyTreeOf
in interfacePropertyTreeOwner
- Parameters:
type
- ThePropertyType
of thePropertyTree
we want to fetch- Returns:
- The PropertyTree or null if this PropertyTreeOwner does not manage a PropertyTree for the given PropertyType or if a null PropertyType is given
-
findChildByName
@Nonnull public java.util.Optional<PerspectiveElement> findChildByName(@Nonnull java.util.Iterator<java.lang.String> pathIterator)
Attempts to locate a child at a given path. If the iterator is exhausted (hasNext() returns false), then this method will return itself. Otherwise, the iterator's values are interpreted as names of children and this method will call into a child's implementation of findChildByName.- Specified by:
findChildByName
in interfaceComponent
- Parameters:
pathIterator
- an iterator whose next value is the name of a child of this component, or if the iterator is exhausted, then this component is the one that will be returned.- Returns:
- an optional of the component being searched for, empty if not found.
-
getChild
public java.util.Optional<Component> getChild(int childId)
-
getChildren
public java.util.Collection<Component> getChildren()
- Specified by:
getChildren
in interfaceComponent
-
getView
public ViewModel getView()
- Specified by:
getView
in interfacePerspectiveElement
- Returns:
- The view within which this element exists, or null if this is a Page or Session
-
createPropertyReference
@Nonnull public PropertyReference createPropertyReference(java.lang.String referencePath, java.util.function.Consumer<PropertyTreeChangeEvent> subscriber, java.util.Set<Origin> acceptableOrigins)
Description copied from interface:PerspectiveElement
Create aPropertyReference
with thisPerspectiveElement
as the target.- Specified by:
createPropertyReference
in interfacePerspectiveElement
- Parameters:
referencePath
- the path to the propertysubscriber
- the subscriber - aConsumer
ofPropertyTreeChangeEvent
sacceptableOrigins
- theSet
ofOrigin
s in which the subscriber is interested- Returns:
- the
PropertyReference
-
getAuditSnapshot
@Nonnull public AuditContext.Builder getAuditSnapshot()
- Specified by:
getAuditSnapshot
in interfaceAuditingContext
- Returns:
- A new, or extended,
AuditContext.Builder
, with qualified information about the current scope.
-
-