Running Long Tasks Walkthrough

A long task is a process that takes a long time to manipulate a data object. In this example, we will create two tasks, one of unknown length (the progress bar on the bottom right is active but shows no percentage of progress) and another one of known length (the progress bar on the bottom right is active and shows increasing progress). Both processes take 10 seconds and will be made accessible to the end-user from a contextual menu of a seismic layer.

Reviewing Dependencies

The creation of a menu item requires five INT modules that are part of the INTViewer platform:

  • IntviewerCore
  • SeismicData
  • Viewer2D
  • Lookup API (provided with Netbeans)
  • Utilities API (provided with Netbeans)

See the list of INTViewer modules to load the INTViewer platform and for a description of each module.

Creating your module template using NetBeans wizard

  • Click File -> New Project
  • In the New Project wizard select NetBeans Modules from the Categories list and Module from the Projects list and click Next >
  • For Project Name, specify mydemoworkflowmodule
  • Select option Standalone Module and make sure to specify the INTViewer platform in the NetBeans Platform field.
  • Click Next > and specify com.mycompany.myviewer.mydemolongtask for the Code Name Base and MyDemoLongTaskModule for the Module Display Name.
  • Check Generate XML Layer (if this option is not present, check the Registering the layer.xml file article)
  • Click on Finish
  • In the Projects tree view, you should see your project which includes a number of files that have been created for you

Configuring your Module

  • In the Projects tree, right click on the module MyDemoLongTaskModule and select Properties from the list.
  • Under Categories, select Libraries.
  • Select Java plaform JDK1.7 . If you don't see this option, you will need to install jdk1.7 and load it into NetBeans using option Tools->Java Platforms
  • Click on the Add button next to Module Dependencies
  • In the list, select IntviewerCore, Lookup, SeismicData, Utilities API, Viewer2D and click OK.
  • Click OK in Project Properties Dialog

Creating a Long Task class (unknown length)

    • In the Projects tree, right click on the module MyDemoLongTaskModule and select New -> Java Class... from the list.
  • Enter DemoLongTaskWithUnknownLength as Class Name and select com.mycompany.myviewer.mydemolongtask as Package.
  • Make this class implement ILongTask<ISeismicData>
  • Automatically add an import for ISeismicData and ILongTask
  • Automatically create the skeleton of required methods for this class
  • Customize the class' implementation as follow:

The DemoLongTaskWithUnknownLength.java file is available from the attachments at the bottom of this page.

Creating a Long Task class (known length)

    • In the Projects tree, right click on the module MyDemoLongTaskModule and select New -> Java Class... from the list.
  • Enter DemoLongTaskWithKnownLength as Class Name and select com.mycompany.myviewer.mydemolongtask as Package.
  • Make this class implement ILongTask<ISeismicData>
  • Automatically add an import for ISeismicData and ILongTask
  • Automatically create the skeleton of required methods for this class
  • Customize the class' implementation as follow:

The DemoLongTaskWithKnownLength.java file is available from the attachments at the bottom of this page.

Create a Layer Action Class for the first long task

    • In the Projects tree, right click on the module MyDemoLongTaskModule and select New -> Java Class... from the list.
  • Enter DemoRunLongTaskWithUnknownLengthAction as Class Name and select com.mycompany.myviewer.mydemolongtask as Package.
  • Make this class extend AbstractLayerAction
  • Automatically add an import for AbstractLayerAction
  • Automatically create the skeleton of required methods for this class
  • Customize the class' implementation as follow:

You can download the DemoRunLongTaskWithUnknownLengthAction.java file from the attachments at the bottom of this page.

Create a Layer Action Class for the second long task

    • In the Projects tree, right click on the module MyDemoLongTaskModule and select New -> Java Class... from the list.
  • Enter DemoRunLongTaskWithKnownLengthAction as Class Name and select com.mycompany.myviewer.mydemolongtask as Package.
  • Make this class extend AbstractLayerAction
  • Automatically add an import for AbstractLayerAction
  • Automatically create the skeleton of required methods for this class
  • Customize the class' implementation as follow:

You can download the DemoRunLongTaskWithKnownLengthAction.java file from the attachments at the bottom of this page.

Creating a layer.xml file

  • Customize the layer.xml file as follow:

A walkthrough about the customization of layer.xml for contextual menus is available.

You can download the layer.xml file from the attachments at the bottom of this page.

Running both actions

    • Click the green arrow in the toolbar.
    • Load a seismic X-Section using File -> Open Data in New X-Section Window -> Seismic...
    • Open a seismic data file in the file dialog box
  • Right click the layer
  • Select DemoRunLongTaskWithKnownLengthActionDisplayName

A progress bar is displayed on the bottom right of the screen. This progress bar has a percentage displayed.

  • Select DemoRunLongTaskWithKnownLengthActionDisplayName

A progress bar is displayed on the bottom right of the screen. This progress bar doesn't have a percentage displayed.

More information about long tasks is available in the references section.