| package aeri.rcp; |
| |
| import javax.inject.Inject; |
| |
| import org.eclipse.e4.core.contexts.IEclipseContext; |
| import org.eclipse.e4.ui.di.UISynchronize; |
| import org.eclipse.e4.ui.services.IServiceConstants; |
| import org.eclipse.jface.dialogs.PopupDialog; |
| import org.eclipse.swt.SWT; |
| import org.eclipse.swt.graphics.Point; |
| import org.eclipse.swt.graphics.Rectangle; |
| import org.eclipse.swt.widgets.Composite; |
| import org.eclipse.swt.widgets.Control; |
| import org.eclipse.swt.widgets.Label; |
| import org.eclipse.swt.widgets.Shell; |
| |
| /** |
| * Primitive, not fully implemented notification service. For illustration purpose only. |
| */ |
| public class DemoNotificationSupport { |
| |
| private UISynchronize sync; |
| private IEclipseContext context; |
| |
| @Inject |
| public DemoNotificationSupport(UISynchronize sync, IEclipseContext context) { |
| this.sync = sync; |
| this.context = context; |
| } |
| |
| private PopupDialog popup; |
| |
| public void showNewLogEventNotification(LogEvent group) { |
| sync.asyncExec(new Runnable() { |
| |
| @Override |
| public void run() { |
| closePopup(); |
| Shell parent = (Shell) context.get(IServiceConstants.ACTIVE_SHELL); |
| popup = new NewLogEventPopup(parent); |
| popup.open(); |
| } |
| |
| }); |
| } |
| |
| public void showNewResponseNotification(LogEvent group) { |
| sync.asyncExec(new Runnable() { |
| |
| @Override |
| public void run() { |
| closePopup(); |
| Shell parent = (Shell) context.get(IServiceConstants.ACTIVE_SHELL); |
| popup = new NewResponsePopup(parent); |
| popup.open(); |
| } |
| }); |
| } |
| |
| private void closePopup() { |
| if (popup != null) { |
| popup.close(); |
| } |
| } |
| |
| private abstract static class NotificationPopup extends PopupDialog { |
| |
| private static final int POPUP_OFFSET = 20; |
| |
| public NotificationPopup(Shell parent) { |
| super(parent, PopupDialog.INFOPOPUPRESIZE_SHELLSTYLE | SWT.MODELESS, false, false, false, false, false, "An error was logged.", |
| null); |
| setBlockOnOpen(false); |
| } |
| |
| @Override |
| protected Point getInitialLocation(Point initialSize) { |
| Shell parent = getParentShell(); |
| Point parentSize, parentLocation; |
| |
| if (parent != null) { |
| parentSize = parent.getSize(); |
| parentLocation = parent.getLocation(); |
| } else { |
| Rectangle bounds = getShell().getDisplay().getBounds(); |
| parentSize = new Point(bounds.width, bounds.height); |
| parentLocation = new Point(0, 0); |
| } |
| // We have to take parent location into account because SWT considers all |
| // shell locations to be in display coordinates, even if the shell is parented. |
| return new Point(parentSize.x - initialSize.x + parentLocation.x - POPUP_OFFSET, |
| parentSize.y - initialSize.y + parentLocation.y - POPUP_OFFSET); |
| } |
| } |
| |
| private static class NewLogEventPopup extends NotificationPopup { |
| |
| public NewLogEventPopup(Shell parent) { |
| super(parent); |
| } |
| |
| @Override |
| protected Control createDialogArea(Composite parent) { |
| setTitleText("An Error was Logged Popup"); |
| |
| Composite container = (Composite) super.createDialogArea(parent); |
| Label label = new Label(container, SWT.NONE); |
| label.setText("An error was logged. Please... - TODO create your app specifc popup"); |
| return container; |
| } |
| } |
| |
| private static class NewResponsePopup extends NotificationPopup { |
| |
| public NewResponsePopup(Shell parent) { |
| super(parent); |
| } |
| |
| @Override |
| protected Control createDialogArea(Composite parent) { |
| setTitleText("Thank you!"); |
| Composite container = (Composite) super.createDialogArea(parent); |
| Label label = new Label(container, SWT.NONE); |
| label.setText("You report was forwarded to the service team for triage. Thank you for reporting this issue."); |
| return container; |
| } |
| } |
| } |