Skip Navigation

Creating a Basic Text Notification

In a Java editor, create the Notification entity object by adding the code that is shown below. You can also use additional methods in the Notification object. A basic text notification is shown in the following figure.

image032
    final Notification notification = new Notification();
    notification.setWindowTitle("Title");
    notification.setPriority(Priority.LOW);
    notification.setContent("Content");
    notification.setLeftSideBarColor(SideBarColor.GREEN);
    notification.setNotificationTime(30000);

        Where:

setWindowTitle() adds the title of the notification dialog.

setPriority() adds the priority of the notification. The options are, from least to most important, LOW, NORMAL, HIGH, and CRITICAL.

setContent() adds the text content of the notification.

setLeftSideBarColor() adds the color of the notification. The options are GREEN, RED, and YELLOW.

setNotificationTime() adds the time in milliseconds when you want the notification to be visible to end-users.

  1. Display the notification in a UI thread. Add the code that is shown below to the code in the previous step. If the method that calls createNotification() is already in the SWT UI thread, you do not need the special UiThreadInvoker.

        final INotificationService service = Activator.getDefault().getNotificationService();
        UiThreadInvoker <Object> invoker = new UiThreadInvoker <Object>() {
            protected Object invoke() {
                service.createNotification(notification);
                return null;
            }
        };
        invoker.asyncExec();
  1. Save your Java code.