Altova MapForce 2025 Professional Edition

Listing the Properties of a MapForce Mapping

Home Prev Top Next

The listing below shows how a Mapping object in MapForce can be loaded as a table and prepared for modal activation.

 

 

01 //access MapForce Java-COM bridge

02 import com.altova.automation.MapForce.*;

03 import com.altova.automation.MapForce.Component;

04 import com.altova.automation.MapForce.Enums.ENUMComponentUsageKind;

05

06 //access AWT and Swing components

07 import java.awt.*;

08 import javax.swing.*;

09 import javax.swing.table.*;

10

11

12 /**

13  * A simple example of a table control loading the structure from a Mapping object.

14  * The class receives an Mapping object, loads its components in a JTable, and prepares

15  * for modal activation.

16  *

17  * Feel free to modify and extend this sample.

18  *

19  * @author Altova GmbH

20  */

21 class MapForceTable extends JDialog

22 {

23   /**

24    * The table control

25    */

26   private JTable myTable;

27  

28   /**

29    * Constructor that prepares the modal dialog containing the filled table control

30    * @param mapping The data to be displayed in the table

31    * @param parent  Parent frame

32    */

33   public MapForceTable( Mapping mapping, Frame parent )

34   {

35     // Construct the modal dialog

36     super( parent, "MapForce component table", true );

37     // Build up the tree

38     fillTable( mapping );

39     // Arrange controls in the dialog

40     setContentPane( new JScrollPane( myTable ) );

41   }

42

43   /**

44    * Loads the components of a Mapping object in the table

45    * @param mapping Source data

46    */

47   private void fillTable( Mapping mapping)

48   {

49     try

50     {

51       // count how many Instance components do we have

52       int size = 0;

53       for (Component comp : mapping.getComponents())

54         if ( comp.getUsageKind() == ENUMComponentUsageKind.eComponentUsageKind_Instance )

55           ++size;

56      

57       // Prepare data

58       final String[] columnNames = { "Component", "Has inputs", "Has outputs", "Input file", "Output file", "Schema" };

59       final Object[][] data = new Object[size ][ 7 ] ;

60       int index = 0 ;

61       for (Component comp : mapping.getComponents())

62         if ( comp.getUsageKind() == ENUMComponentUsageKind.eComponentUsageKind_Instance )

63         {

64           int i = 0;

65           data[ index ][ i++ ] = comp.getName() ;

66           data[ index ][ i++ ] = new Boolean( comp.getHasIncomingConnections() );

67           data[ index ][ i++ ] = new Boolean( comp.getHasOutgoingConnections() );

68           data[ index ][ i++ ] = comp.getInputInstanceFile();

69           data[ index ][ i++ ] = comp.getOutputInstanceFile();

70           data[ index++ ][ i ] = comp.getSchema() ;

71         }

72      

73       // Set up table

74       myTable = new JTable( new AbstractTableModel() {

75           public String getColumnName(int col) { return columnNames[col]; }

76           public int getRowCount() { return data.length; }

77           public int getColumnCount() { return columnNames.length; }

78           public Object getValueAt(int row, int col) { return data[row][col]; }

79           public boolean isCellEditable(int row, int col) { return false; }

80           public Class getColumnClass(int c) { return getValueAt(0, c).getClass(); }          

81       } );

82      

83       // Set width

84       for( index = 0 ; index < columnNames.length ; ++index )

85         myTable.getColumnModel().getColumn( index ).setMinWidth( 80 );

86       myTable.getColumnModel().getColumn( 5 ).setMinWidth( 400 );

87     }

88     catch (Exception e)

89     {

90       e.printStackTrace();

91     }

92   }

93

94 }

 

© 2018-2024 Altova GmbH