Event Handling
Events Fired by the Process Manager Engine
Java beans must place any data needed, to persist in the DataModel. Although the DataModel serves the dual purpose of persisting data and sharing it across various beans, certain beans may choose to place data in the DataModel purely for the purpose of persisting. Such beans may choose to place their data in the DataModel only when the project is being saved, and retrieve their data from the DataModel right after the project has been opened.
The Process Manager engine fires an event (com.altair.hwm.beans.utils.events.HWMEvent) just prior to saving the project file. Beans can add themselves as listeners to the event (in their SetFrameWork method).
import com.altair.hwm.interfaces.*;
public class MyClass extends JButton
implements IHWMControl, ActionListener, HWMEventListener
.
.
.
/**
* This method is called by the HWPM engine to set the interface with
* which a bean can communicate directly with the HWPM classes.
* @param hwmFrameWork The interface with which a bean can
* communicate with HWPM.
*/
public void SetFrameWork(IHWMFrameWork hwmFrameWork)
m_hwmFrameWork = hwmFrameWork;
hwmFrameWork.AddHWMEventListener(this);
ReadProperties();
}
/**
* This method is called when the execution of a method succeeds
* @param hwmEvent The event object that contains the event info
*/
public void HWMEventCallback(HWMEvent hwmEvent)
if (hwmEvent.GetEventType() == HWMEvent.SAVE)
SaveProperties();
}
/**
* Save the required properties in the datamodel
* (so that they persist)
*/
public void SaveProperties()
//Get the datamodel
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
//Background color
hwmDataModel.SetProperty(m_strBeanName+"::BACKGROUND_COLOR",
super.getBackground());
}
/**
* Get the required properties from the datamodel and initialize self
*/
public void ReadProperties()
//Get the datamodel
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
//Background color
Color color = (Color) hwmDataModel.GetProperty(
m_strBeanName+"::BACKGROUND_COLOR");
if (color != null) this.setBackground(color);
}
.
.
.
}
If your bean extends HWMBasePanel or HWMButton, and so on, the base class is implementing HWMEventListener. The base class implementation SetFrameWork method has also added "this" as listener to HWMEvent. Your bean needs to override the methods SaveProperties and ReadProperties only.
import com.altair.hwm.interfaces.*;
import com.altair.hw.beans.utils.*;
public class MyClass extends HWMButton implements ActionListener
.
.
.
/**
* This method is called by the HWPM engine to set the interface with
* which a bean can communicate directly with the HWPM classes.
* @param hwmFrameWork The interface with which a bean can
* communicate with HWPM.
*/
public void SetFrameWork(IHWMFrameWork hwmFrameWork)
super.SetFrameWork(hwmFrameWork);
}
/**
* Save the required properties in the datamodel
* (so that they persist)
*/
public void SaveProperties()
//The base class saves the following properties...
//Background, Foreground colors, font, Enabled & Visible flags
super.SaveProperties();
//Get the datamodel
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
// Mesh Size
hwmDataModel.SetProperty(m_strBeanName+"::MESH_SIZE",
new Double (m_dMeshSize));
}
/**
* Get the required properties from the datamodel and initialize self
*/
public void ReadProperties()
//The base class saves the following properties...
//Background, Foreground colors, font, Enabled & Visible flags
super.ReadProperties();
//Get the datamodel
IHWMDataModel hwmDataModel = m_hwmFrameWork.GetDataModel();
//Mesh Size
Double dMeshSize = (Double) hwmDataModel.GetProperty(
m_strBeanName+"::MESH_SIZE");
if (dMeshSize!= null) m_dMeshSize = dMeshSize.dooubleValue();
}
.
.
.
}
Event(s) Fired by the Bean
It is a good practice for the beans to fire an event (HWMCmdEvent) after the successful completion of whatever the bean is supposed to do.
This will be very useful in event-method binding. For example, the "Mesh" bean is supposed to execute one of its methods after the "Import Model" bean successfully completes its operation. Bindings are not encouraged.
public class MyClass extends HWMButton implements ActionListener
.
.
.
/**
* The main function wherein, something will be done when the
* button is pressed
*/
public void DoSomething()
.
.
.
fireOnCmdSuccess(new HWMCmdEvent(this, 1, "DO_SOMETHING"));
}
.
.
.
}