Home

Awesome

<img align="left" src="durian-swt.png"> DurianSwt: Reactive utilities and fluent builders for SWT

<!---freshmark shields output = [ link(shield('Maven central', 'mavencentral', 'com.diffplug.durian:durian-swt', 'blue'), 'https://search.maven.org/artifact/com.diffplug.durian/durian-swt'), link(shield('Apache 2.0', 'license', 'apache-2.0', 'blue'), 'https://tldrlegal.com/license/apache-license-2.0-(apache-2.0)'), '', link(shield('Changelog', 'changelog', versionLast, 'brightgreen'), 'CHANGES.md'), link(shield('Javadoc', 'javadoc', 'yes', 'brightgreen'), 'https://javadoc.io/static/com.diffplug.durian/durian-swt/{{versionLast}}/overview-summary.html'), link(shield('Live chat', 'gitter', 'chat', 'brightgreen'), 'https://gitter.im/diffplug/durian'), link(image('Travis CI', 'https://travis-ci.org/diffplug/durian-swt.svg?branch=master'), 'https://travis-ci.org/diffplug/durian-swt'), ].join('\n'); -->

Maven central Apache 2.0

Changelog Javadoc Live chat Travis CI

<!---freshmark /shields --> <!---freshmark javadoc output = prefixDelimiterReplace(input, 'https://javadoc.io/static/com.diffplug.durian/durian-swt/', '/', versionLast); -->

Infrastructure

SwtExec.async().guardOn(textBox).subscribe(serverResponse, txt -> {
  textBox.setText(txt);
});

Fluent builders

void textOkCanel(Composite cmp) {
  Layouts.setGrid(cmp).numColumns(3);

  // instructions fill the full width
  Text text = new Text(cmp, SWT.WRAP);
  Layouts.setGridData(text).horizontalSpan(3).grabAll();

  // right-justified ok / cancel buttons
  Layouts.newGridPlaceholder(cmp).grabHorizontal();
  Button btnOk = new Button(cmp, SWT.PUSH);
  Layouts.setGridData(btn).widthHint(SwtMisc.defaultButtonWidth());
  Button btnCancel = new Button(cmp, SWT.PUSH);
  Layouts.setGridData(btn).widthHint(SwtMisc.defaultButtonWidth());
}
Shells.builder(SWT.DIALOG_TRIM, this::textOkCanel)
  .setTitle("Confirm operation")
  .setSize(SwtMisc.defaultDialogWidth(), 0) // set the width, pack height to fit contents
  .openOnDisplayBlocking();
ColumnViewerFormat<Person> format = ColumnViewerFormat.builder();
format.setStyle(SWT.SINGLE | SWT.FULL_SELECTION);
format.addColumn().setText("First").setLabelProviderText(Person::getFirstName);
format.addColumn().setText("Last").setLabelProviderText(Person::getLastName);
format.addColumn().setText("Age").setLabelProviderText(p -> Integer.toString(p.getAge())).setLayoutPixel(3 * SwtMisc.systemFontWidth());
TableViewer table = format.buildTable(parent);
TreeViewer tree = format.buildTree(parent);

Resource management

Interactive testing

Ideally, all UI code would have fully automated UI testing, but such tests are time-consuming to write, so they often just don't get written at all. InteractiveTest bridges the gap by making it easy to write user-in-the-loop guided tests. Furthermore, these tests can even be run in a headless enviroment on a CI server, where the test UI will be opened, then automatically closed after a timeout. This ensures that the tests are all in working order and ready for a human tester to do final validation.

InteractiveTest

From ViewerMiscTest.java:

String message = StringPrinter.buildStringFromLines(
  "- The table and the tree should keep their selection in sync.",
  "- The table and the tree should not allow multi-selection.",
  "- The categories in the tree should not be selectable.");
InteractiveTest.testCoat(message, cmp -> {
  TableAndTree tableAndTree = new TableAndTree(cmp, SWT.SINGLE);

  // get the selection of the tree
  RxBox<Optional<TreeNode<String>>> treeSelection = ViewerMisc.<TreeNode<String>> singleSelection(tableAndTree.tree)
      // only names can be selected - not categories
      .enforce(opt -> opt.map(val -> isName(val) ? val : null));

  // sync the tree and the table
  RxOptional<TreeNode<String>> tableSelection = ViewerMisc.singleSelection(tableAndTree.table);
  Rx.subscribe(treeSelection, tableSelection::set);
  Rx.subscribe(tableSelection, treeSelection::set);
});

Miscellaneous stuff

String installerExtension = OS.getNative().winMacLinux("exe","dmg","sh");
String helperBinary = "driver_" + Arch.getNative().x86x64("", "_64") + ".dll";
String swtJarName = "org.eclipse.swt." + SwtPlatform.getRunning();
<!---freshmark /javadoc -->

Requirements

Durian requires:

Acknowledgements