Виджет уведомлений в приложении RCP - PullRequest
0 голосов
/ 05 июня 2019

Я ищу виджет или компонент (SWT), который позволяет мне уведомлять пользователя о завершении фоновой работы.Мне известны такие вещи, как MyLyn , которые предоставляют способы создания системных уведомлений.Тем не менее, я бы предпочел виджет, который отображает уведомления в моем окне.Есть ли какой-нибудь существующий виджет, который я не смог найти?

Спасибо.

[РЕДАКТИРОВАТЬ] Я видел, что компонент делает более или менее то, что я хочу.Он используется в отчете об ошибках затмения, как описано здесь: https://eclipsesource.com/blogs/2015/06/23/error-reporting-top-eclipse-mars-feature-2/ Однако я не могу найти базовый виджет, используемый здесь.

Ответы [ 2 ]

0 голосов
/ 06 июня 2019

Я предлагаю вам изучить Уведомление о туманности . Возможно, вам придется настроить его для уведомления внутри вашего приложения

Взял ниже код фрагмент

public class NotifierSnippet {
    /**
     * @param args
     */
    public static void main(final String[] args) {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setText("Notifier Snippet");
        shell.setSize(200, 200);
        shell.setLayout(new FillLayout(SWT.VERTICAL));

        final int[] counter = new int[1];
        counter[0] = 0;

        // Yellow theme (default)
        final Button testerYellow = new Button(shell, SWT.PUSH);
        testerYellow.setText("Push me [Yellow theme]!");
        testerYellow.addListener(SWT.Selection, event -> {
            Notifier.notify("New Mail message", "Laurent CARON (lcaron@...)<br/><br/>Test message #" + counter[0] + "...");
            counter[0]++;
        });

        // Blue theme
        final Button testerBlue = new Button(shell, SWT.PUSH);
        testerBlue.setText("Push me [Blue theme]!");
        testerBlue.addListener(SWT.Selection, event -> {
            Notifier.notify("New Mail message", "Laurent CARON (lcaron@...)<br/><br/>Test message #" + counter[0] + "...", NotifierTheme.BLUE_THEME);
            counter[0]++;
        });

        // Grey theme
        final Button testerGrey = new Button(shell, SWT.PUSH);
        testerGrey.setText("Push me [Gray theme]!");
        testerGrey.addListener(SWT.Selection, event -> {
            Notifier.notify("New Mail message", "Laurent CARON (lcaron@...)<br/><br/>Test message #" + counter[0] + "...", NotifierTheme.GRAY_THEME);
            counter[0]++;
        });

        shell.open();

        while (!shell.isDisposed()) {
            if (!display.readAndDispatch()) {
                display.sleep();
            }
        }
        display.dispose();
    }
}
0 голосов
/ 05 июня 2019

Вы можете использовать всплывающую подсказку как уведомление, которое появится в панели задач на панели задач.Ниже приведен фрагмент кода, который вы можете попробовать.В окнах он появляется как маленькое черное всплывающее окно в правом нижнем углу.Я предоставил кнопку только для симуляции.Вы можете реализовать по-своему, когда закончится фоновая длительная задача.

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.ToolTip;
import org.eclipse.swt.widgets.Tray;
import org.eclipse.swt.widgets.TrayItem;

public class ToolTipBalloon {

  public static void showNotificationPopup(Shell shell) {
    ToolTip tip = new ToolTip(shell, SWT.BALLOON | SWT.ICON_INFORMATION);
    tip.setMessage("Your Notification Message");
    Display display = shell.getDisplay();
    Tray tray = display.getSystemTray();
    if (tray != null) {
      TrayItem item = new TrayItem(tray, SWT.NONE);
      //      Image image = new Image(display, "yourFile.gif");
      //      item.setImage(image);
      tip.setText("Notification from a Windows Tray");
      item.setToolTip(tip);
    } else {
      tip.setText("Notification from anywhere");
      tip.setLocation(400, 400);
    }
    tip.setVisible(true);
  }

  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);

    // To simulate notification
    Button notifyBtn = new Button(shell, SWT.PUSH);
    notifyBtn.setText("Press for Notification");
    notifyBtn.addListener(
        SWT.Selection,
        new Listener() {
          public void handleEvent(Event event) {
            showNotificationPopup(shell);
          }
        });
    notifyBtn.pack();
    shell.setBounds(50, 50, 200, 100);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
}
...