Chapter 4 – Interacting with the User

Understanding menus

1. A command can be associated with a handler to provide a menu item. Handlers are indirection mechanisms that allow the same menu (example Copy) to take on different commands based on which context they are in. It is also possible to have a default command id associated with a menu to avoid this indirection.

2. The M1 key is an alias for Cmd on macOS, and for Ctrl on other platforms. When defining standard commands like copy (M1+C) it has the expected behaviour on both platforms (Cmd + C for macOS and Ctrl + C for others).

3. Keystrokes are bound to commands via a binding, which lists the key(s) necessary to invoke and the associated command/handler.

4. A menu's locationURI is where it will contribute the entry to the UI. These are specified either as relative to an existing menu's contribution, or to its generic additions entry. It is also possible to specify custom ones which are associated with custom code.

5. A pop-up menu is created by adding a menu to the part descriptor, and then enabling contributions by registering with the EMenuService.

Understanding jobs

1. The syncExec() will block and wait for the job to complete before continuing code. The asyncExec() will continue to run after posting the job but before it completes.

2. The UISynchronize instance can be used to run jobs on UI and non-SWT UI threads.

3. The UIJob will always run on the UI thread of the runtime, and direct access of widgets will not run into a thread error. Care should be taken to minimize the amount of time spent in the UI thread so as not to block Eclipse. The Job will run on a non-UI thread, and so does not have access to acquire or modify UI-threaded objects.

4. The Status.OK_STATUS singleton is used to indicate success in general. Although it is possible to instantiate a Status object with an OK code, doing so only increases the garbage collection as the Status result is typically discarded after execution.

5. The CommandService can be injected using DI by using @Inject ICommandService into the E4 view.

6. An icon can be displayed by setting a property on the Job with the name IProgressConstants2.ICON_NAME.

7. SubMonitors are generally easier to use at the start of a method, to ensure that the monitor being passed in is correctly partitioned as appropriate for the task in hand. The SubProgressMonitor should generally not be used.

8. The cancellation should be checked as frequently as possible, so that as soon as the user clicks on cancel, the job is aborted.

Understanding errors

1. An informational dialog is shown with MessageDialog.openInformation() (and .openWarning() and .openError() as well). There is also a MessageDialog.openConfirmation(), which returns the value of a yes/no answer to the user.

2. The StatusReporter provides a means to report statuses such that they can be handled appropriately, but without a UI association.

3. Status reporting is asynchronous by default, although a BLOCK option exists to make it synchronous.

4. To combine the results of many things into one report, use a MultiStatus object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.204.8