Skip to content

Commit 6fdfb6f

Browse files
committed
Improve JFace notification snippets and documentation
- Fix typo in Snippet001 filename (Notifcation -> Notification) - Fix inconsistent indentation in Snippet084 - Simplify Snippet085 to use builder API idiomatically instead of reparenting widgets - Add Snippet001 to JFaceSnippets.md - Clean up Notification section in JFaceSnippets.md: remove duplicate links, fix typos, improve descriptions See #1226
1 parent e199306 commit 6fdfb6f

5 files changed

Lines changed: 55 additions & 92 deletions

File tree

docs/JFaceSnippets.md

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,35 +43,28 @@ The JFace ColorSelector widget is a convenient composition of button and color s
4343
Notification
4444
------------
4545

46-
### [Snippet081 - Notification API](https://raw.githubusercontent.com/eclipse-platform/eclipse.platform.ui/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/dialogs/Snippet081NotificationPopup.java)
46+
### [Snippet001 - Simple Notification Popup with Strings](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet001NotificationPopupWithStrings.java)
4747

48-
* [Snippet081 - Notication API](https://raw.githubusercontent.com/eclipse-platform/eclipse.platform.ui/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/dialogs/Snippet081NotificationPopup.java)
48+
Demonstrates the simplest usage of the `NotificationPopup` builder API with `forShell()` and plain strings for title and content.
4949

50-
51-
Demonstrates usage of the non-blocking notification API
50+
### [Snippet081 - Notification API](https://raw.githubusercontent.com/eclipse-platform/eclipse.platform.ui/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/dialogs/Snippet081NotificationPopup.java)
51+
52+
Demonstrates usage of the non-blocking notification API with `forShell()`, showing notifications triggered by button clicks.
5253

53-
5454
![Snippet081 Shell1.gif](images/Snippet081_Shell1.gif)
5555

5656
### [Snippet083 - Notification Popup with Functions](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet083NotificationPopupWithFunctions.java)
5757

58-
* [Snippet083 - Notification Popup with Functions](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet083NotificationPopupWithFunctions.java)
59-
60-
Demonstrates the creation of notification popups that include function callbacks for user interactions.
58+
Demonstrates the creation of notification popups using `Function<Composite, Control>` for custom title and content creation.
6159

6260
### [Snippet084 - Notification Popup with Custom Delay and Fade](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet084NotificationPopupWithCustomDelayAndFade.java)
6361

64-
* [Snippet084 - Notification Popup with Custom Delay and Fade](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet084NotificationPopupWithCustomDelayAndFade.java)
65-
66-
Shows how to create notification popups with custom delay and fade effects for enhanced visual feedback.
67-
68-
### [Snippet085 - Notification popup with user interaction](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet085NotificationPopupWithUserInteraction.java)
62+
Shows how to create notification popups with custom delay and fade-in effects using the `delay()` and `fadeIn()` builder methods.
6963

70-
This snippet demonstrates how to create a `NotificationPopup` that includes user interaction with a button. When the button is clicked, a confirmation dialog is shown.
64+
### [Snippet085 - Notification Popup with User Interaction](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet085NotificationPopupWithUserInteraction.java)
7165

72-
For the full code, please visit the [GitHub repository](https://github.com/eclipse-platform/eclipse.platform.ui/blob/master/examples/org.eclipse.jface.snippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippets/notifications/Snippet085NotificationPopupWithUserInteraction.java).
66+
Demonstrates a `NotificationPopup` with interactive content — a label and a button that opens a confirmation dialog when clicked.
7367

74-
7568
![Snippet085.png](images/Snippet085NotificationPopupWithUserInteraction.png)
7669

7770

examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/notifications/Snippet001NotifcationPopupWithStrings.java renamed to examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/notifications/Snippet001NotificationPopupWithStrings.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
import org.eclipse.swt.widgets.Display;
55
import org.eclipse.swt.widgets.Shell;
66

7-
public class Snippet001NotifcationPopupWithStrings {
7+
public class Snippet001NotificationPopupWithStrings {
88

99
public static void main(String[] args) {
1010
Display display = new Display();
11+
Shell shell = new Shell(display);
12+
shell.setSize(400, 200);
13+
shell.open();
14+
15+
NotificationPopup.forShell(shell).text("Just a notification").title("Test", true).open();
1116

12-
NotificationPopup.forDisplay(display).text("Just a notification").title("Test", true).open();
13-
Shell shell = display.getShells()[0];
1417
while (!shell.isDisposed()) {
1518
if (!display.readAndDispatch())
1619
display.sleep();

examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/notifications/Snippet083NotificationPopupWithFunctions.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ public class Snippet083NotificationPopupWithFunctions {
1414

1515
public static void main(String[] args) {
1616
Display display = new Display();
17+
Shell shell = new Shell(display);
18+
shell.setSize(400, 200);
19+
shell.open();
1720

1821
Function<Composite, Control> contentCreator = WidgetFactory.label(SWT.NONE)
1922
.text("Just a notification")::create;
2023
Function<Composite, Control> titleCreator = WidgetFactory.label(SWT.NONE).text("Test")::create;
2124

22-
NotificationPopup.forDisplay(display).content(contentCreator).title(titleCreator, true).open();
25+
NotificationPopup.forShell(shell).content(contentCreator).title(titleCreator, true).open();
2326

24-
Shell shell = display.getShells()[0];
2527
while (!shell.isDisposed()) {
2628
if (!display.readAndDispatch())
2729
display.sleep();

examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/notifications/Snippet084NotificationPopupWithCustomDelayAndFade.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,18 @@ public class Snippet084NotificationPopupWithCustomDelayAndFade {
88

99
public static void main(String[] args) {
1010
Display display = new Display();
11+
Shell shell = new Shell(display);
12+
shell.setSize(400, 200);
13+
shell.open();
1114

12-
NotificationPopup.forDisplay(display).text("Just a notification").title("Test", false).delay(500)
13-
.fadeIn(true).open();
15+
NotificationPopup.forShell(shell).text("Just a notification").title("Test", false).delay(500).fadeIn(true)
16+
.open();
1417

15-
Shell shell = display.getShells()[0];
16-
while (!shell.isDisposed()) {
17-
if (!display.readAndDispatch())
18-
display.sleep();
19-
}
18+
while (!shell.isDisposed()) {
19+
if (!display.readAndDispatch())
20+
display.sleep();
21+
}
2022

21-
display.dispose();
23+
display.dispose();
2224
}
23-
}
25+
}

examples/org.eclipse.jface.snippets/Eclipse JFace Snippets/org/eclipse/jface/snippets/notifications/Snippet085NotificationPopupWithUserInteraction.java

Lines changed: 25 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,71 +4,34 @@
44
import org.eclipse.jface.notifications.NotificationPopup;
55
import org.eclipse.jface.widgets.WidgetFactory;
66
import org.eclipse.swt.SWT;
7-
import org.eclipse.swt.graphics.Font;
8-
import org.eclipse.swt.layout.GridData;
9-
import org.eclipse.swt.layout.GridLayout;
10-
import org.eclipse.swt.widgets.Button;
11-
import org.eclipse.swt.widgets.Composite;
127
import org.eclipse.swt.widgets.Display;
13-
import org.eclipse.swt.widgets.Label;
148
import org.eclipse.swt.widgets.Shell;
159

1610
public class Snippet085NotificationPopupWithUserInteraction {
1711

18-
public static void main(String[] args) {
19-
Display display = new Display();
20-
Shell shell = new Shell(display); // Create the shell
21-
22-
// Set the size of the shell
23-
shell.setSize(400, 200);
24-
25-
// Create content for the notification popup
26-
Composite contentComposite = new Composite(shell, SWT.NONE);
27-
GridLayout layout = new GridLayout();
28-
layout.marginWidth = 10; // Margin width
29-
layout.marginHeight = 10; // Margin height
30-
contentComposite.setLayout(layout);
31-
32-
// Create a bold label with wrapped text
33-
Label firstLine = new Label(contentComposite, SWT.WRAP);
34-
firstLine.setText("It is recommended that you");
35-
Font boldFont = new Font(display, "Arial", 10, SWT.BOLD);
36-
firstLine.setFont(boldFont);
37-
// Create a bold label with wrapped text
38-
Label secondLine = new Label(contentComposite, SWT.WRAP);
39-
secondLine.setText("update your configuration");
40-
secondLine.setFont(boldFont);
41-
42-
43-
// Create a button that will show the confirmation dialog when clicked
44-
Button button = new Button(contentComposite, SWT.PUSH);
45-
button.setText("Confirm");
46-
47-
button.addListener(SWT.Selection, event -> {
48-
MessageDialog.openConfirm(shell, "Confirmation", "Button was pressed!");
49-
});
50-
51-
// Set GridData for button to align properly in the layout
52-
GridData gridData = new GridData(SWT.LEFT, SWT.CENTER, false, false);
53-
button.setLayoutData(gridData);
54-
55-
// Create the notification popup
56-
NotificationPopup.forDisplay(display)
57-
.content(composite -> {
58-
contentComposite.setParent(composite);
59-
return composite;
60-
})
61-
.title(composite -> WidgetFactory.label(SWT.NONE).text("System update!!!").create(composite), true)
62-
.open();
63-
64-
shell.open(); // Open the shell
65-
66-
while (!shell.isDisposed()) {
67-
if (!display.readAndDispatch())
68-
display.sleep();
69-
}
70-
71-
boldFont.dispose(); // Dispose of the font when done
72-
display.dispose();
73-
}
12+
public static void main(String[] args) {
13+
Display display = new Display();
14+
Shell shell = new Shell(display);
15+
shell.setSize(600, 400);
16+
shell.open();
17+
18+
NotificationPopup.forShell(shell)
19+
.content(parent -> {
20+
WidgetFactory.label(SWT.WRAP).text("It is recommended that you\nupdate your configuration")
21+
.create(parent);
22+
WidgetFactory.button(SWT.PUSH).text("Confirm")
23+
.onSelect(e -> MessageDialog.openConfirm(shell, "Confirmation", "Button was pressed!"))
24+
.create(parent);
25+
return parent;
26+
})
27+
.title("System update", true)
28+
.open();
29+
30+
while (!shell.isDisposed()) {
31+
if (!display.readAndDispatch())
32+
display.sleep();
33+
}
34+
35+
display.dispose();
36+
}
7437
}

0 commit comments

Comments
 (0)