For some actions, such as the Edit Chassis action in Example: Example Command Class, you must obtain a reference to the target vSphere object that the user selected before performing the action. You can obtain a reference to the target vSphere object by using the
ActionInvocationEvent that the Actions Framework generates when an action is triggered.
The ActionInvocationEvent contains an object of type
ActionContext in the Actions Framework library. The
ActionContext object contains an array named
targetObjects, from which you can obtain references to all vSphere objects that the user has selected in the user interface. In
Example: Example Command Class, the method
getIResourceReference shows an example of how to obtain a reference to the target object.
Your command class must import the packages com.vmware.actionsfw.ActionContext and
com.vmware.actionsfw.events.ActionInvocationEvent to use these vSphere Web Client SDK features.
To dispatch a ModelChangeEvent, your command class must import the packages
com.vmware.data.common.OperationType,
com.vmware.data.common.ObjectChangeInfo, and
com.vmware.data.common.events.ModelChangeEvent. You must also annotate your command class as follows.
You can use a callback method to ensure that your command class dispatches the necessary ModelChangeEvent. Your service proxy class can invoke the callback method in your command class when the action operation finishes. In
Example: Example Command Class, the command class passes references to the appropriate callback methods,
onEditChassisComplete and
onCreateChassisComplete, when it invokes the action operations in the service proxy. The callback methods then process the results of the action operation and dispatch the
ModelChangeEvent as necessary.