Altova XMLSpy 2025 Enterprise Edition

The code listing below shows how basic events can be handled. When calling the XMLSpyControl’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 XMLSpyDocumentControl’s open method.

 

 

01       // Open the PXF file when button is pressed

02       btnOpenPxf.addActionListener( new ActionListener() {

03         public void actionPerformed(ActionEvent e) {

04           try {

05             xmlSpyControl.open( strExamplesFolder + "OrgChart.pxf" );

06           } catch (AutomationException e1) {

07             e1.printStackTrace();

08           }

09         }

10       } );

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

12   {

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

14     if ( !i_bFileAlreadyOpened )

15     {

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

17       try {

18         XMLSpyContainer.xmlSpyDocument.open( i_strFileName );

19         XMLSpyContainer.xmlSpyDocument.requestFocusInWindow();

20       } catch (Exception e) {

21         e.printStackTrace();

22       }

23     }

24   }

© 2018-2024 Altova GmbH