Altova MapForce 2025 Professional Edition

The code listing below shows how basic events can be handled. When calling the MapForceControl’s open method, or when trying to open a file via the menu or Project tree, the onOpenedOrFocused event is sent to the attached event handler. The basic handling for this event is opening the file by calling the MapForceDocumentControl’s open method.

 

 

01       // Open the Marketing file when button is pressed

02       btnMarkExp.addActionListener( new ActionListener() {

03         public void actionPerformed(ActionEvent e) {

04           try {

05             // Instruct the Document control to open the file - avoid calling the open method of MapForceControl (see help)

06             mapForceDocument.open( strExamplesFolder + "MarketingExpenses.mfd" );

07             mapForceDocument.requestFocusInWindow();

08           } catch (AutomationException e1) {

09             e1.printStackTrace();

10           }

11         }

12       } );

13       public void onOpenedOrFocused( String i_strFileName, boolean i_bOpenWithThisControl, boolean i_bFileAlreadyOpened ) throws AutomationException

14   {

15     // Handle the New/Open events coming from the Project tree or from the menus

16     if ( !i_bFileAlreadyOpened )

17     {

18       // This is basically an SDI interface, so open the file in the already existing document control

19       try {

20         MapForceContainer.mapForceDocument.open( i_strFileName );

21         MapForceContainer.mapForceDocument.requestFocusInWindow();

22       } catch (Exception e) {

23         e.printStackTrace();

24       }

25     }

26   }

 

© 2018-2024 Altova GmbH