Additional File Content

By adding its own BeanInfo class you can customize newly created bean component's properties. Use the MyFirstBean.java and MyFirstBean.mf file while creating user bean.

MyFirstBean.java file content

package com.tutorial;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import java.io.*;
import java.beans.*;
import java.util.*;
 
import com.altair.hwm.interfaces.*;

/**
* Title:        MyFirstBean
* Description:  The First Bean that we are writing as part of the training
* Copyright     Copyright (c) 2001
* Company:      Altair Engineering, Inc.
* @author surya
*/
public class MyFirstBean extends JPanel
                      implements ActionListener, IHWMControl
{
   /**
    * The handle to the HWPM FrameWork that will handed by the HWPM engine
    */
   protected IHWMFrameWork m_hwmFrameWork = null;
   protected String m_strBeanName;

   /**
    * UI components used in this bean
    */
   protected JTextField m_txtFile = null;
   protected JButton m_btnImport = null;
   protected JButton m_btnFileBrowser = null;

   /**
    * Constructor
    */

   public MyFirstBean()
   {
       try
       {
           jbInit();
       }
       catch(Exception e)
       {
           e.printStackTrace();
       }
   }

   /**
    * Builds GUI
    * @throws Exception
    */
   private void jbInit() throws Exception
   {
       //Set the layout of this panel as GridbagLayout
       setLayout(new GridBagLayout());

       //Create and add listeners to UI components
       JLabel lblFile = new JLabel("File");
       m_txtFile = new JTextField("");
       m_btnImport  = new JButton("Import");
       m_btnImport.addActionListener(this);
       m_btnFileBrowser = new JButton("Browse...");

       //Add tooltips
       m_txtFile.setToolTipText("File to be imported into HM");
       m_btnFileBrowser.setToolTipText("File Browser");
       m_btnImport.setToolTipText("Import the file in Hypermesh");

       //Add the components to the panel
       this.add(lblFile,  new GridBagConstraints(0, 0, 1, 1, 0.0, 1.0,
           GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
           new Insets(9, 9, 9, 3), 0, 0));
       this.add(m_txtFile,  new GridBagConstraints(1, 0, 1, 1, 1.0, 1.0,
           GridBagConstraints.NORTHWEST, GridBagConstraints.HORIZONTAL,
           new Insets(9, 3, 9, 3), 0, 0));
       this.add(m_btnFileBrowser, new GridBagConstraints(2, 0, 1, 1, 0.0, 1.0,
           GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
           new Insets(9, 3, 9, 3), 0, 0));
       this.add(m_btnImport, new GridBagConstraints(3, 0, 1, 1, 0.0, 1.0,
           GridBagConstraints.NORTHWEST, GridBagConstraints.NONE,
           new Insets(9, 3, 9, 9), 0, 0));
   }

   /**
    * Callback for import model button and file type combo box
    */
   public void actionPerformed(ActionEvent event)
   {
       Object objSource = event.getSource();

       try
       {
           if(objSource == m_btnImport)
           {
               ImportModel();
           }
       }
       catch (Exception exception)
       {
           exception.printStackTrace();
       }
   }

   /**
    * Imports the selected model into Hypermesh
    * @throws Exception
    */
   public void ImportModel() throws Exception
   {
       JOptionPane.showMessageDialog(null, "Hello World");
   }

   /////////////////////// IHWMControl Interface ////////////////////////////

   /**
    * This method is called by the HWPM engine to set the interface with
    * which the 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)
   {
       JOptionPane.showMessageDialog(null, "Came to SetFramework()");
       m_hwmFrameWork = hwmFrameWork;
   }

 

   /**
    * Set the name of the bean
    * @param strBeanName The name of this bean as the framework knows it to be.
    * Will be useful, if the bean chooses to scope its data in the datamodel -
    * especially if multiple instances of the same bean appear in the process
    */
   public void SetBeanName(String strBeanName)
   {
       m_strBeanName = strBeanName;
   }

   /**
    * Invoked by the HWM application when the bean is being destroyed. Any
    * uninitializations to be done, can be done here by overriding this method.
    */
   public void OnExit()
   {
   }

   /**
    * Invoked by the HWM application when all the beans are loaded and the
    * application can run. Beans that need to perform some action once all
    * the beans are loaded can do it here. The container will call 'Run' on
    * all the beans that have implemented the IHWMControl. The order will be:
    * a> First call "Run" on all the beans in pages associated with a task.
    *    Begin with the first task.
    * b> Call 'Run' on rest of the pages (which are not associated with a
    *    task). The pages are selected based on their order of creation.
    * c> Within a page, the beans are invoked depending on the order of their
    *    creation.
    */
   public void Run()
   {
   }

   /**
    * The play method needs to execute the functionaliy. This may be invoked
    * in the replay mode.
    */
   public void Play()
   {
   }
}

MyFirstBean.mf file content

Manifest-Version: 1.0

Name: com/tutorial/MyFirstBean.class
Java-Bean: True
Sealed: True

So far you have created a Java bean and used the bean in a process template. Now, run a process template in Stand-alone mode by using the script given below.

Below is the Batch Script [Save to *.bat file].

Note: Please edit the ALTAIR_HOME variable appropriately.

Please edit the DEF_TEMPLATE variable appropriately.

REM HWVERSION_9.0b115_Mar 16 2008_12:24:42
@echo off
REM Altair Copyright
REM -------------------------------------------------------------------------------
REM HyperWorks Process Manager Startup Script (PC ONLY)
REM -------------------------------------------------------------------------------

if "%OS%" == "Windows_NT" setlocal
set ALTAIR_HOME=C:\Altair\hw9.0
set OS_BITS=win32
set HW_MSG_HELP=%ALTAIR_HOME%\
set HW_MSG_HOME=%ALTAIR_HOME%\

set DEF_TEMPLATE=C:\surya\F_DRIVE\Altair_Works\temp\s.pmt

set HWPM_HOME=%ALTAIR_HOME%\javaapps\%OS_BITS%\pmgr
set ALTAIR_JIDE_LIB="%HWPM_HOME%\lib\jide-action.jar;%HWPM_HOME%\lib\jide-components.jar;%HWPM_HOME%\lib\jide-designer.jar;%HWPM_HOME%\lib\jide-dialogs.jar;%HWPM_HOME%\lib\jide-dock.jar;%HWPM_HOME%\lib\jide-grids.jar"
set ALTAIR_MONARCH_LIB="%HWPM_HOME%\lib\mchart.jar;%HWPM_HOME%\lib\mgraph.jar"
REM -------------------------------------------------------------------------------
REM Set the path to the default license file.
REM -------------------------------------------------------------------------------
if "%LM_LICENSE_FILE%" == "" set LM_LICENSE_FILE=%ALTAIR_HOME%\security\altair_lic.dat
set JRE_HOME=%ALTAIR_HOME%\hw\jre\%OS_BITS%\jre
REM echo %JRE_HOME%
set JRE_ARGS=-DHWPM_HOME="%HWPM_HOME%" -DALTAIR_HOME="%ALTAIR_HOME%" -DHWS_PATH="%ALTAIR_HOME%\hw\lib\%OS_BITS%" -Xmx512M -DHW_MSG_HELP=%HW_MSG_HELP% -DHW_MSG_HOME=%HW_MSG_HOME%
set ALTAIR_CLASSPATH="%HWPM_HOME%\bin\hwpm.jar;%ALTAIR_CLASSPATH%"
set ALTAIR_CLASSNAME=com.altair.hwm.toolkit.frame.HWMAppFrameView
REM ------------------------------------------------------------------------------
REM Uncomment for debugging
REM ------------------------------------------------------------------------------
REM ${JRE_HOME}/bin/java ${JRE_ARGS} -Ddebug=true  -classpath ${ALTAIR_CLASSPATH} ${ALTAIR_CLASSNAME} &
REM ------------------------------------------------------------------------------
REM echo "%JRE_HOME%\bin\javaw" %JRE_ARGS% -classpath %ALTAIR_CLASSPATH% %ALTAIR_CLASSNAME%
"%JRE_HOME%\bin\javaw" %JRE_ARGS% -Ddeftpl=%DEF_TEMPLATE% -classpath %ALTAIR_JIDE_LIB%;%ALTAIR_MONARCH_LIB%;%ALTAIR_CLASSPATH% %ALTAIR_CLASSNAME%