UI Integration & Toolbar Implementation

With your command and handler defined in the previous module, the final step is to expose this functionality to the user by integrating it into the MineTwin toolbar.

Starting Point

This section builds on the content from Introduction to Custom Commands and Handlers.

1. Navigating the UI Model

We will insert the new import button into the primary toolbar area. Open Application.e4xmi and follow this path in the Model Explorer:

  • Windows > Trimmed Window > Trim Bars > Trim Bar – Top > Toolbar (First)

    Eclipse IDE window showing an XML configuration tree with toolbar and tool items highlighted within a trimmed window section.

    Right-click on the Toolbar instance then Add child > Handled ToolItem to begin adding your new button.

2. Creating the Tool Item

In the properties for this new tool item:

  1. In the Label field, add our previous Command name from before CustomImportBlocks.

  2. Find the Command field and select the CustomImportBlocks command from your command list.

    UI dialog titled "Handled Tool Item" with fields for ID, Type, Label, Tooltip, and options for visibility and rendering.
  3. Adding an Icon: Visual cues are vital for user experience. You can use any .png file here.

There are some default icons in MineTwin. Set the Icon URI path to: platform:/plugin/com.amalgamasimulation.minetwin.application/icons/importCSV.png

3. Running and Testing

Now that the button is bound to your handler, perform a full application test to ensure the lifecycle works as expected.

3.1. Initial State Verification

When you launch the MineTwin application, observe the toolbar immediately.

  • Expected Outcome: The import button should be greyed out (disabled).

  • Why? Because our @CanExecute logic requires a scenario to be loaded, and on startup, the active scenario is null.

3.2. Functional Testing

  1. Load a valid scenario into MineTwin. (You can use one of the Standard Library Scenarios for this.)

  2. Observe the button. It should now become active (no longer greyed out).

  3. Click the button to trigger your import logic.

  4. Validation: Because we have not yet built the UI for parsing the file, check the Eclipse Console view. You should see the file path of your selected Excel file printed there.

    Initial Button Output to Console

If you do not see the file path in the console, revisit the CustomImportBlocksHandler.java class to ensure you have correctly implemented the @Execute method, and verify that the handler is correctly bound to the command in the E4 model.

4. Summary of Workflow

You have now successfully:

  1. Declared a command in the model.

  2. Implemented the executable logic in a handler class.

  3. Bound these together via the E4 UI model.

  4. Created a conditional UI trigger (the button) that respects the application state.

This pattern is the standard for extending MineTwin functionality. You can now replicate these steps to add new features or export functionality as needed.