Skip to content

Commit 78f2847

Browse files
committed
Big update to Durian SWT's docs.
1 parent b342a22 commit 78f2847

File tree

2 files changed

+61
-4
lines changed

2 files changed

+61
-4
lines changed

README.md

+61-4
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414

1515
* [`ControlWrapper`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/ControlWrapper.html) - create custom widgets which properly encapsulate their base control.
1616
* [`Coat`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/Coat.html) - a functional interface for populating an empty Composite.
17+
* [`CoatMux`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/CoatMux.html) - a mechanism for layering and swapping Coats.
1718
* [`SwtExec`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/SwtExec.html) - an `ExecutorService` which executes on the SWT thread.
18-
* [`SwtExec.Guarded`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/SwtExec.Guarded.html) - an `Executor` which is tied to the lifetime of an SWT widget. Say goodbye to `SWTException: Widget is disposed` forever! It can also subscribe to any kind of observable (Guava's ListenableFuture or RxJava's Observable), see [DurianRx](https://github.com/diffplug/durian-rx) for more info.
19+
* [`SwtExec.Guarded`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/SwtExec.Guarded.html) - an `ExecutorService` which is tied to the lifetime of an SWT widget. Say goodbye to `SWTException: Widget is disposed` forever! It can also subscribe to any kind of observable (Guava's ListenableFuture or RxJava's Observable), see [DurianRx](https://github.com/diffplug/durian-rx) for more info.
20+
1921
```java
2022
SwtExec.async().guardOn(textBox).subscribe(serverResponse, txt -> {
2123
textBox.setText(txt);
@@ -46,17 +48,68 @@ void textOkCanel(Composite cmp) {
4648
* [`Shells`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/Shells.html) - dialogs without boilerplate
4749

4850
```java
49-
Shells.create(SWT.DIALOG_TRIM, this::textOkCanel)
51+
Shells.builder(SWT.DIALOG_TRIM, this::textOkCanel)
5052
.setTitle("Confirm operation")
5153
.setSize(SwtMisc.defaultDialogWidth(), 0) // set the width, pack height to fit contents
5254
.openOnDisplayBlocking();
5355
```
5456

57+
* [`Actions`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/jface/Actions.html) - builder and one-liner:
58+
`Actions.create("Redo", this::redo);`
59+
60+
* [`LabelProviders`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/jface/LabelProviders.html) - builder and one-liner:
61+
`LabelProviders.createWithText(Person::getName)`
62+
63+
* [`ColumnFormat`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/ColumnFormat.html) and [`ColumnViewerFormat`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/jface/ColumnViewerFormat.html) - dialogs without boilerplate
64+
65+
```java
66+
ColumnViewerFormat<Person> format = ColumnViewerFormat.createWithStyle(style | SWT.FULL_SELECTION);
67+
format.addColumn().setText("First").setLabelProviderText(Person::getFirstName);
68+
format.addColumn().setText("Last").setLabelProviderText(Person::getLastName);
69+
format.addColumn().setText("Age").setLabelProviderText(p -> Integer.toString(p.getAge())).setLayoutPixel(3 * SwtMisc.systemFontWidth());
70+
TableViewer table = format.buildTable(parent);
71+
TreeViewer tree = format.buildTree(parent);
72+
```
73+
5574
### Resource management
5675

5776
* [`OnePerWidget`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/OnePerWidget.html) - a cache tied to the lifetime of an SWT Widget.
5877
* [`ColorPool`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/ColorPool.html) - a pool of colors tied to the lifetime of a widget. `ColorPool.forWidget(widget).getColor(rgbValue)`
59-
* [`ImageDescriptors`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/ImageDescriptors.html) - use ImageDescriptors with proper resource sharing. `ImageDescriptors.set(btn, imageDescriptor)`
78+
* [`ImageDescriptors`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/jface/ImageDescriptors.html) - use ImageDescriptors with proper resource sharing. `ImageDescriptors.set(btn, imageDescriptor)`
79+
80+
### Interactive testing
81+
82+
Ideally, all UI code would have fully automated UI testing, but
83+
such tests are time-consuming to write, so they often just don't
84+
get written at all. [`InteractiveTest`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/InteractiveTest.html)
85+
bridges the gap by making it easy to write user-in-the-loop guided tests. Furthermore,
86+
these tests can even be run in a [headless enviroment on a CI server](https://github.com/diffplug/durian-swt/blob/master/build.gradle#L66-L93), where the test UI
87+
will be opened, then automatically closed after a timeout. This ensures that the tests
88+
are all in working order and ready for a human tester to do final validation.
89+
90+
![InteractiveTest](interactive-test.png)
91+
92+
From [`ViewerMiscTest.java`](https://github.com/diffplug/durian-swt/blob/master/test/com/diffplug/common/swt/jface/ViewerMiscTest.java):
93+
94+
```java
95+
String message = StringPrinter.buildStringFromLines(
96+
"- The table and the tree should keep their selection in sync.",
97+
"- The table and the tree should not allow multi-selection.",
98+
"- The categories in the tree should not be selectable.");
99+
nteractiveTest.testCoat(message, cmp -> {
100+
TableAndTree tableAndTree = new TableAndTree(cmp, SWT.SINGLE);
101+
102+
// get the selection of the tree
103+
RxBox<Optional<TreeNode<String>>> treeSelection = ViewerMisc.<TreeNode<String>> singleSelection(tableAndTree.tree)
104+
// only names can be selected - not categories
105+
.enforce(opt -> opt.map(val -> isName(val) ? val : null));
106+
107+
// sync the tree and the table
108+
RxOptional<TreeNode<String>> tableSelection = ViewerMisc.singleSelection(tableAndTree.table);
109+
Rx.subscribe(treeSelection, tableSelection::set);
110+
Rx.subscribe(tableSelection, treeSelection::set);
111+
});
112+
```
60113

61114
### Miscellaneous stuff
62115

@@ -66,7 +119,8 @@ Shells.create(SWT.DIALOG_TRIM, this::textOkCanel)
66119
+ `systemFontHeight/Width`, `scaleByFont`, `scaleByFontHeight` - resolution-independent sizes.
67120
+ `treeDefControl`, `treeDefComposite` - a [`TreeDef`](http://diffplug.github.io/durian/javadoc/snapshot/com/diffplug/common/base/TreeDef.html) for traversing UI elements.
68121
+ `setEnabledDeep` - sets the enabled status of every child, grandchild, etc. of the given composite.
69-
122+
* [`SwtRx`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/SwtRx.html) - methods for converting SWT events and models to RxJava Observables.
123+
* [`SwtDebug`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/SwtDebug.html) - utilities for debugging SWT events.
70124
* [`OS`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/os/OS.html), [`Arch`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/os/Arch.html), and [`SwtPlatform`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/os/SwtPlatform.html) - detect things about the running system, and manipulate the SWT jars for build tools.
71125
+ These do not require SWT or JFace, so you can add DurianSwt to your gradle or maven dependencies without needing to also figure out the SWT messiness.
72126
+ You can also just copy-paste these straight into your own code - they have no external dependencies.
@@ -75,6 +129,9 @@ String installerExtension = OS.getNative().winMacLinux("exe","dmg","sh");
75129
String helperBinary = "driver_" + Arch.getNative().x86x64("", "_64") + ".dll";
76130
String swtJarName = "org.eclipse.swt." + SwtPlatform.getRunning();
77131
```
132+
* [`ViewerMisc`](http://diffplug.github.io/durian-swt/javadoc/snapshot/com/diffplug/common/swt/jface/ViewerMisc.html) - useful static methods for JFace viewers.
133+
+ `singleSelection`, `multiSelection` - returns an RxBox for listening to and setting the selection of a viewer.
134+
+ `setTreeContentProvider`, `setLazyTreeContentProvider` - uses a TreeDef to provide the content of a TreeViewer.
78135

79136
## Requirements
80137

interactive-test.png

14.9 KB
Loading

0 commit comments

Comments
 (0)