HyperWorks Tools

Beans

Beans

Previous topic Next topic Expand/collapse all hidden text  

Beans

Previous topic Next topic JavaScript is required for expanding text JavaScript is required for the print function  
hmtoggle_plus1greyBuilding JAVA Beans
1.Open Eclipse.  
2.From the File menu, select New, then Project. A dialog box will appear titled New Project.

openeclipse_10

3.Select Java Project from the dialog box options.

javabean

4.Click Next.
5.A New Java Project dialog will appear. Enter project name MyFirstBean.

newjava

6. Click Finish. You are now able to view your project.

newjavaproject_10

7.Right-click your project name, MyFirstBean, and select Build Path, then Add Libraries from the menu.

buildpath_10

8.An Add Library dialog box will appear. Select User Library.

addlibrary_10

9.Click Next.

10. Select the User Libraries button located on the right hand side of the Add Library dialog box. A Preferences (Filtered) dialog box is displayed.

userlibrary_10

11.Click New located on the right hand side of the dialog box.

preferencesfilter

12.A New User Library dialog is displayed. Enter the library name PM_LIBS.

13. Click OK. The library name, PM_LIBS, will now appear under the Defined user libraries box in the Preferences (Filtered) panel.

newuserlibrary

14.Select the library name and click the Add JARs button.

pm_libs

 

15.Browse for the JAR files in the Altair installations directory.
<<ALTAIR_HOME>>\javaapps\win32\pmgr\lib
16.Select all JAR files and click OK.
Note:In UNIX Environment, check with administrator on where Altair installation is located for pmgr/lib directory.
17.After adding the JAR files to the PM_LIBS library, your screen should look like this:

pm_libslist

 

18.Create a new user library titled PM_CONTROLS, by clicking on the New button.

pmcontrols

19.Click OK.

PM_CONTROLS will now appear in the Preferences (Filtered) panel, under the Defined user libraries.

20.Select PM_CONTROLS and click the Add JARs...button.
21.Add JAR files to the library by selecting the files from the directory <<ALTAIR_HOME>>\javaapps\win32\pmgr\controls

These files should be added to the PM_CONTROLS library

“dbbeans.jar “ form <<ALTAIR_HOME>>\javaapps\win32\pmgr\controls\database

“hmsuit.jar “ form <<ALTAIR_HOME>>\javaapps\win32\pmgr\controls\hm

“hwmtils.jar “ form <<ALTAIR_HOME>>\javaapps\win32\pmgr\controls\utils

After adding the JAR files, your dialog box should look like the screen shot below.

pmcontroljarfiles

 

22.Click OK. An Add Library dialog box will appear with both PM_CONTROLS and PM_LIBS listed.
23.Click Finish.

userlibraryendbmp_10

You are now ready to create your first bean.

hmtoggle_plus1greyCreating a Bean

The Eclipse window will look like the screen below with PM_CONTROLS and PM_LIBS libraries listed.

1.Write a JAVA code.

createbean

Note: MyFirstBean.java and MyFirstBean.mf are available at the end of this document.

javacode

2.Create the manifest file, with the content shown below, at the root of the MyFirstBean directory.

javacode1        

3.Export “MyFirstBean” as JAR file to control directory,

C:\SampleBeans\MyTemplate\controls\MyFristBean.jar

Create the template file under “C:\SampleBeans\MyTemplate” directory as

C:\SampleBeans\MyTemplate \sample.pmt

Now, your JAR or bean control is ready to use in process manager templates.

hmtoggle_plus1greyUsing Beans in Process Manager Templates
1.Open Process Studio.
2.Create a sample.pmt in C:\SampleBeans\MyTemplate.
3.From the View menu, open Control view and select your sample from the Categories pull down menu. The bean is now available for use in the template along with Process Manager.

sample

templateready

4.Drag and drop MyFirstBean on page.

finishbean

hmtoggle_plus1greyAdditional 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 moce by using the script given below.

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

 

NotePlease edit ALTAIR_HOME variable appropriately
Please edit 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%