bamaer commented on code in PR #9544:
URL: https://github.com/apache/hop/pull/9544#discussion_r4618970739


##########
plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/xmljoin/XmlJoinDialog.java:
##########
@@ -89,416 +113,540 @@ public String open() {
 
     buildButtonBar().ok(e -> ok()).cancel(e -> cancel()).build();
 
-    ModifyListener lsMod = e -> input.setChanged();
     changed = input.hasChanged();
-
-    ScrolledComposite wScrolledComposite =
-        new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
-    PropsUi.setLook(wScrolledComposite);
-    FormData fdSc = new FormData();
-    fdSc.left = new FormAttachment(0, 0);
-    fdSc.top = new FormAttachment(wSpacer, 0);
-    fdSc.right = new FormAttachment(100, 0);
-    fdSc.bottom = new FormAttachment(wOk, -margin);
-    wScrolledComposite.setLayoutData(fdSc);
-    wScrolledComposite.setLayout(new FillLayout());
-    wScrolledComposite.setExpandHorizontal(true);
-    wScrolledComposite.setExpandVertical(true);
-
-    Composite wContent = new Composite(wScrolledComposite, SWT.NONE);
-    PropsUi.setLook(wContent);
-    FormLayout contentLayout = new FormLayout();
-    contentLayout.marginWidth = PropsUi.getFormMargin();
-    contentLayout.marginHeight = PropsUi.getFormMargin();
-    wContent.setLayout(contentLayout);
-
-    // Target Group
-    Group gTarget = new Group(wContent, SWT.NONE);
-    gTarget.setText(BaseMessages.getString(PKG, "XmlJoin.TargetGroup.Label"));
-    FormLayout targetLayout = new FormLayout();
-    targetLayout.marginHeight = margin;
-    targetLayout.marginWidth = margin;
-    gTarget.setLayout(targetLayout);
-    PropsUi.setLook(gTarget);
-    FormData fdTarget = new FormData();
-    fdTarget.left = new FormAttachment(0, 0);
-    fdTarget.right = new FormAttachment(100, 0);
-    fdTarget.top = new FormAttachment(wSpacer, margin);
-    gTarget.setLayoutData(fdTarget);
-    // Target XML transform line
-    Label wlTargetXMLtransform = new Label(gTarget, SWT.RIGHT);
-    wlTargetXMLtransform.setText(BaseMessages.getString(PKG, 
"XmlJoin.TargetXMLTransform.Label"));
-    PropsUi.setLook(wlTargetXMLtransform);
-    FormData fdlTargetXMLtransform = new FormData();
-    fdlTargetXMLtransform.left = new FormAttachment(0, 0);
-    fdlTargetXMLtransform.top = new FormAttachment(wSpacer, margin);
-    fdlTargetXMLtransform.right = new FormAttachment(middle, -margin);
-    wlTargetXMLtransform.setLayoutData(fdlTargetXMLtransform);
-    wTargetXmlTransform = new CCombo(gTarget, SWT.BORDER | SWT.READ_ONLY);
-    wTargetXmlTransform.setEditable(true);
-    PropsUi.setLook(wTargetXmlTransform);
-    wTargetXmlTransform.addModifyListener(lsMod);
-    FormData fdTargetXMLtransform = new FormData();
-    fdTargetXMLtransform.left = new FormAttachment(middle, 0);
-    fdTargetXMLtransform.top = new FormAttachment(wSpacer, margin);
-    fdTargetXMLtransform.right = new FormAttachment(100, 0);
-    wTargetXmlTransform.setLayoutData(fdTargetXMLtransform);
-
-    // Target XML Field line
-    Label wlTargetXMLfield = new Label(gTarget, SWT.RIGHT);
-    wlTargetXMLfield.setText(BaseMessages.getString(PKG, 
"XmlJoin.TargetXMLField.Label"));
-    PropsUi.setLook(wlTargetXMLfield);
-    FormData fdlTargetXMLfield = new FormData();
-    fdlTargetXMLfield.left = new FormAttachment(0, 0);
-    fdlTargetXMLfield.right = new FormAttachment(middle, -margin);
-    fdlTargetXMLfield.top = new FormAttachment(wTargetXmlTransform, margin);
-    wlTargetXMLfield.setLayoutData(fdlTargetXMLfield);
-
-    wTargetXmlField = new TextVar(variables, gTarget, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wTargetXmlField);
-    wTargetXmlField.addModifyListener(lsMod);
-    FormData fdTargetXMLfield = new FormData();
-    fdTargetXMLfield.left = new FormAttachment(middle, 0);
-    fdTargetXMLfield.top = new FormAttachment(wTargetXmlTransform, margin);
-    fdTargetXMLfield.right = new FormAttachment(100, -margin);
-    wTargetXmlField.setLayoutData(fdTargetXMLfield);
-
-    // Source Group
-    Group gSource = new Group(wContent, SWT.NONE);
-    gSource.setText(BaseMessages.getString(PKG, "XmlJoin.SourceGroup.Label"));
-    FormLayout sourceLayout = new FormLayout();
-    sourceLayout.marginHeight = margin;
-    sourceLayout.marginWidth = margin;
-    gSource.setLayout(sourceLayout);
-    PropsUi.setLook(gSource);
-    FormData fdSource = new FormData();
-    fdSource.left = new FormAttachment(0, 0);
-    fdSource.right = new FormAttachment(100, 0);
-    fdSource.top = new FormAttachment(gTarget, margin);
-    gSource.setLayoutData(fdSource);
-    // Source XML transform line
-    Label wlSourceXMLtransform = new Label(gSource, SWT.RIGHT);
-    wlSourceXMLtransform.setText(BaseMessages.getString(PKG, 
"XmlJoin.SourceXMLTransform.Label"));
-    PropsUi.setLook(wlSourceXMLtransform);
-    FormData fdlSourceXMLtransform = new FormData();
-    fdlSourceXMLtransform.left = new FormAttachment(0, 0);
-    fdlSourceXMLtransform.top = new FormAttachment(wTargetXmlField, margin);
-    fdlSourceXMLtransform.right = new FormAttachment(middle, -margin);
-    wlSourceXMLtransform.setLayoutData(fdlSourceXMLtransform);
-    wSourceXmlTransform = new CCombo(gSource, SWT.BORDER | SWT.READ_ONLY);
-    wSourceXmlTransform.setEditable(true);
-    PropsUi.setLook(wSourceXmlTransform);
-    wSourceXmlTransform.addModifyListener(lsMod);
-    FormData fdSourceXMLtransform = new FormData();
-    fdSourceXMLtransform.left = new FormAttachment(middle, 0);
-    fdSourceXMLtransform.top = new FormAttachment(wTargetXmlField, margin);
-    fdSourceXMLtransform.right = new FormAttachment(100, 0);
-    wSourceXmlTransform.setLayoutData(fdSourceXMLtransform);
-
-    // Source XML Field line
-    Label wlSourceXMLfield = new Label(gSource, SWT.RIGHT);
-    wlSourceXMLfield.setText(BaseMessages.getString(PKG, 
"XmlJoin.SourceXMLField.Label"));
-    PropsUi.setLook(wlSourceXMLfield);
-    FormData fdlSourceXMLfield = new FormData();
-    fdlSourceXMLfield.left = new FormAttachment(0, 0);
-    fdlSourceXMLfield.right = new FormAttachment(middle, -margin);
-    fdlSourceXMLfield.top = new FormAttachment(wSourceXmlTransform, margin);
-    wlSourceXMLfield.setLayoutData(fdlSourceXMLfield);
-
-    wSourceXmlField = new TextVar(variables, gSource, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wSourceXmlField);
-    wSourceXmlField.addModifyListener(lsMod);
-    FormData fdSourceXMLfield = new FormData();
-    fdSourceXMLfield.left = new FormAttachment(middle, 0);
-    fdSourceXMLfield.top = new FormAttachment(wSourceXmlTransform, margin);
-    fdSourceXMLfield.right = new FormAttachment(100, -margin);
-    wSourceXmlField.setLayoutData(fdSourceXMLfield);
-
-    // Join Group
-    Group gJoin = new Group(wContent, SWT.NONE);
-    gJoin.setText(BaseMessages.getString(PKG, "XmlJoin.JoinGroup.Label"));
-    FormLayout joinLayout = new FormLayout();
-    joinLayout.marginHeight = margin;
-    joinLayout.marginWidth = margin;
-    gJoin.setLayout(joinLayout);
-    PropsUi.setLook(gJoin);
-    FormData fdJoin = new FormData();
-    fdJoin.left = new FormAttachment(0, 0);
-    fdJoin.right = new FormAttachment(100, 0);
-    fdJoin.top = new FormAttachment(gSource, margin);
-    gJoin.setLayoutData(fdJoin);
-
-    // Target XPath line
-    Label wlTargetXPath = new Label(gJoin, SWT.RIGHT);
-    wlTargetXPath.setText(BaseMessages.getString(PKG, 
"XmlJoin.TargetXPath.Label"));
-    PropsUi.setLook(wlTargetXPath);
-    FormData fdlTargetXPath = new FormData();
-    fdlTargetXPath.left = new FormAttachment(0, 0);
-    fdlTargetXPath.right = new FormAttachment(middle, -margin);
-    fdlTargetXPath.top = new FormAttachment(wSourceXmlField, margin);
-    wlTargetXPath.setLayoutData(fdlTargetXPath);
-
-    wTargetXPath = new TextVar(variables, gJoin, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wTargetXPath);
-    wTargetXPath.addModifyListener(lsMod);
-    FormData fdTargetXPath = new FormData();
-    fdTargetXPath.left = new FormAttachment(middle, 0);
-    fdTargetXPath.top = new FormAttachment(wSourceXmlField, margin);
-    fdTargetXPath.right = new FormAttachment(100, -margin);
-    wTargetXPath.setLayoutData(fdTargetXPath);
-
-    // Complex Join Line
-    Label wlComplexJoin = new Label(gJoin, SWT.RIGHT);
-    wlComplexJoin.setText(BaseMessages.getString(PKG, 
"XmlJoin.ComplexJoin.Label"));
-    PropsUi.setLook(wlComplexJoin);
-    FormData fdlComplexJoin = new FormData();
-    fdlComplexJoin.left = new FormAttachment(0, 0);
-    fdlComplexJoin.top = new FormAttachment(wTargetXPath, margin);
-    fdlComplexJoin.right = new FormAttachment(middle, -margin);
-    wlComplexJoin.setLayoutData(fdlComplexJoin);
-    wComplexJoin = new Button(gJoin, SWT.CHECK);
-    PropsUi.setLook(wComplexJoin);
-    FormData fdComplexJoin = new FormData();
-    fdComplexJoin.left = new FormAttachment(middle, 0);
-    fdComplexJoin.top = new FormAttachment(wlComplexJoin, 0, SWT.CENTER);
-    fdComplexJoin.right = new FormAttachment(100, 0);
-    wComplexJoin.setLayoutData(fdComplexJoin);
-    wComplexJoin.addSelectionListener(
-        new SelectionAdapter() {
+    loading = true;
+
+    Label wIntro = new Label(shell, SWT.WRAP | SWT.LEFT);
+    wIntro.setText(BaseMessages.getString(PKG, "XmlJoin.Intro"));
+    PropsUi.setLook(wIntro);
+    FormData fdIntro = new FormData();
+    fdIntro.left = new FormAttachment(0, 0);
+    fdIntro.right = new FormAttachment(100, 0);
+    fdIntro.top = new FormAttachment(wSpacer, margin);
+    wIntro.setLayoutData(fdIntro);
+
+    // The options on the left, the target document on the right
+    SashForm sash = new SashForm(shell, SWT.HORIZONTAL);
+    PropsUi.setLook(sash);
+    FormData fdSash = new FormData();
+    fdSash.left = new FormAttachment(0, 0);
+    fdSash.right = new FormAttachment(100, 0);
+    fdSash.top = new FormAttachment(wIntro, margin);
+    fdSash.bottom = new FormAttachment(wOk, -2 * margin);
+    sash.setLayoutData(fdSash);
+    Composite options = new Composite(sash, SWT.NONE);
+    PropsUi.setLook(options);
+    options.setLayout(new FormLayout());
+    widgets =
+        GuiCompositeWidgets.addScrolledComposite(
+            options, variables, null, null, 
XmlJoinMeta.GUI_PLUGIN_ELEMENT_PARENT_ID, input);
+    wDocument = new TargetDocumentPane(sash, this::loadDocument);
+    wDocument.setPickListener(this::picked);
+    wDocument.setKeyNames(this::keyNames);
+    sash.setWeights(new int[] {60, 40});
+    widgets.setWidgetsListener(
+        new GuiCompositeWidgetsAdapter() {
           @Override
-          public void widgetSelected(SelectionEvent e) {
+          public void widgetModified(
+              GuiCompositeWidgets compositeWidgets, Control changedWidget, 
String widgetId) {
+            if (loading) {
+              return;
+            }
             input.setChanged();
-
-            if (wComplexJoin.getSelection()) {
-              wJoinCompareField.setEnabled(true);
-            } else {
-              wJoinCompareField.setEnabled(false);
+            switch (widgetId) {
+              case XmlJoinMeta.WIDGET_JOIN_MODE -> joinModeChanged();
+              case XmlJoinMeta.WIDGET_TARGET_XPATH -> 
wDocument.show(resolvedXPath());
+              case XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM -> {
+                fillOtherInput(XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM);
+                wDocument.setDocument(null, null);
+              }
+              case XmlJoinMeta.WIDGET_TARGET_XML_FIELD -> 
wDocument.setDocument(null, null);
+              case XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM ->
+                  fillOtherInput(XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM);
+              default -> {
+                // Nothing else depends on another option
+              }
             }
+            updateXPathCheck();
           }
         });
 
-    // Join Compare field line
-    Label wlJoinCompareField = new Label(gJoin, SWT.RIGHT);
-    wlJoinCompareField.setText(BaseMessages.getString(PKG, 
"XmlJoin.JoinCompareFiled.Label"));
-    PropsUi.setLook(wlJoinCompareField);
-    FormData fdlJoinCompareField = new FormData();
-    fdlJoinCompareField.left = new FormAttachment(0, 0);
-    fdlJoinCompareField.right = new FormAttachment(middle, -margin);
-    fdlJoinCompareField.top = new FormAttachment(wComplexJoin, margin);
-    wlJoinCompareField.setLayoutData(fdlJoinCompareField);
-
-    wJoinCompareField = new TextVar(variables, gJoin, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wJoinCompareField);
-    wJoinCompareField.addModifyListener(lsMod);
-    FormData fdJoinCompareField = new FormData();
-    fdJoinCompareField.left = new FormAttachment(middle, 0);
-    fdJoinCompareField.top = new FormAttachment(wComplexJoin, margin);
-    fdJoinCompareField.right = new FormAttachment(100, -margin);
-    wJoinCompareField.setLayoutData(fdJoinCompareField);
-    wJoinCompareField.setEnabled(false);
-
-    // Result Group
-    Group gResult = new Group(wContent, SWT.NONE);
-    gResult.setText(BaseMessages.getString(PKG, "XmlJoin.ResultGroup.Label"));
-    FormLayout resultLayout = new FormLayout();
-    resultLayout.marginHeight = margin;
-    resultLayout.marginWidth = margin;
-    gResult.setLayout(resultLayout);
-    PropsUi.setLook(gResult);
-    FormData fdResult = new FormData();
-    fdResult.left = new FormAttachment(0, 0);
-    fdResult.right = new FormAttachment(100, 0);
-    fdResult.top = new FormAttachment(gJoin, margin);
-    fdResult.bottom = new FormAttachment(100, -50);
-    gResult.setLayoutData(fdResult);
-
-    // Value XML Field line
-    Label wlValueXmlField = new Label(gResult, SWT.RIGHT);
-    wlValueXmlField.setText(BaseMessages.getString(PKG, 
"XmlJoin.ValueXMLField.Label"));
-    PropsUi.setLook(wlValueXmlField);
-    FormData fdlValueXmlField = new FormData();
-    fdlValueXmlField.left = new FormAttachment(0, 0);
-    fdlValueXmlField.right = new FormAttachment(middle, -margin);
-    fdlValueXmlField.top = new FormAttachment(wJoinCompareField, margin);
-    wlValueXmlField.setLayoutData(fdlValueXmlField);
-    wValueXmlField = new TextVar(variables, gResult, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wValueXmlField);
-    wValueXmlField.addModifyListener(lsMod);
-    FormData fdValueXMLfield = new FormData();
-    fdValueXMLfield.left = new FormAttachment(middle, 0);
-    fdValueXMLfield.top = new FormAttachment(wJoinCompareField, margin);
-    fdValueXMLfield.right = new FormAttachment(100, -margin);
-    wValueXmlField.setLayoutData(fdValueXMLfield);
-
-    // Encoding Line
-    Label wlEncoding = new Label(gResult, SWT.RIGHT);
-    wlEncoding.setText(BaseMessages.getString(PKG, "XmlJoin.Encoding.Label"));
-    PropsUi.setLook(wlEncoding);
-    FormData fdlEncoding = new FormData();
-    fdlEncoding.left = new FormAttachment(0, 0);
-    fdlEncoding.top = new FormAttachment(wValueXmlField, margin);
-    fdlEncoding.right = new FormAttachment(middle, -margin);
-    wlEncoding.setLayoutData(fdlEncoding);
-    wEncoding = new CCombo(gResult, SWT.BORDER | SWT.READ_ONLY);
-    wEncoding.setEditable(true);
-    PropsUi.setLook(wEncoding);
-    wEncoding.addModifyListener(lsMod);
-    FormData fdEncoding = new FormData();
-    fdEncoding.left = new FormAttachment(middle, 0);
-    fdEncoding.top = new FormAttachment(wValueXmlField, margin);
-    fdEncoding.right = new FormAttachment(100, 0);
-    wEncoding.setLayoutData(fdEncoding);
-    wEncoding.addFocusListener(
-        new FocusListener() {
-          @Override
-          public void focusLost(FocusEvent e) {
-            // Do nothing
-          }
+    inputTransforms =
+        pipelineMeta
+            .findPreviousTransforms(pipelineMeta.findTransform(transformName), 
true)
+            .stream()
+            .map(TransformMeta::getName)
+            .toArray(String[]::new);
+    setComboItems(XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM, inputTransforms);
+    setComboItems(XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM, inputTransforms);
+    setComboItems(XmlJoinMeta.WIDGET_ENCODING, ConstUi.getEncodings());
+    listFieldsOnFocus(XmlJoinMeta.WIDGET_TARGET_XML_FIELD, 
XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM);
+    listFieldsOnFocus(XmlJoinMeta.WIDGET_SOURCE_XML_FIELD, 
XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM);
+    listFieldsOnFocus(
+        XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD, 
XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM);
+    addXPathCheck();
+    enableKeyField();
+    wDocument.setByKey(joinMode() == XmlJoinMode.BY_KEY);
+    wDocument.show(resolvedXPath());
+    updateXPathCheck();
+
+    loading = false;
+    input.setChanged(changed);
 
-          @Override
-          public void focusGained(FocusEvent e) {
-            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
-            shell.setCursor(busy);
-            setEncodings();
-            shell.setCursor(null);
-            busy.dispose();
-          }
-        });
+    focusTransformName();
+    BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());
 
-    // Complex Join Line
-    Label wlOmitXMLHeader = new Label(gResult, SWT.RIGHT);
-    wlOmitXMLHeader.setText(BaseMessages.getString(PKG, 
"XmlJoin.OmitXMLHeader.Label"));
-    PropsUi.setLook(wlOmitXMLHeader);
-    FormData fdlOmitXMLHeader = new FormData();
-    fdlOmitXMLHeader.left = new FormAttachment(0, 0);
-    fdlOmitXMLHeader.top = new FormAttachment(wEncoding, margin);
-    fdlOmitXMLHeader.right = new FormAttachment(middle, -margin);
-    wlOmitXMLHeader.setLayoutData(fdlOmitXMLHeader);
-    wOmitXmlHeader = new Button(gResult, SWT.CHECK);
-    PropsUi.setLook(wOmitXmlHeader);
-    FormData fdOmitXMLHeader = new FormData();
-    fdOmitXMLHeader.left = new FormAttachment(middle, 0);
-    fdOmitXMLHeader.top = new FormAttachment(wlOmitXMLHeader, 0, SWT.CENTER);
-    fdOmitXMLHeader.right = new FormAttachment(100, 0);
-    wOmitXmlHeader.setLayoutData(fdOmitXMLHeader);
-    wOmitXmlHeader.addSelectionListener(
-        new SelectionAdapter() {
-          @Override
-          public void widgetSelected(SelectionEvent e) {
-            input.setChanged();
-          }
-        });
+    return transformName;
+  }
 
-    Label wlOmitNullValues = new Label(gResult, SWT.RIGHT);
-    wlOmitNullValues.setText(BaseMessages.getString(PKG, 
"XmlJoin.OmitNullValues.Label"));
-    PropsUi.setLook(wlOmitNullValues);
-    FormData fdlOmitNullValues = new FormData();
-    fdlOmitNullValues.left = new FormAttachment(0, 0);
-    fdlOmitNullValues.top = new FormAttachment(wOmitXmlHeader, margin);
-    fdlOmitNullValues.right = new FormAttachment(middle, -margin);
-    wlOmitNullValues.setLayoutData(fdlOmitNullValues);
-    wOmitNullValues = new Button(gResult, SWT.CHECK);
-    PropsUi.setLook(wOmitNullValues);
-    FormData fdOmitNullValues = new FormData();
-    fdOmitNullValues.left = new FormAttachment(middle, 0);
-    fdOmitNullValues.top = new FormAttachment(wlOmitNullValues, 0, SWT.CENTER);
-    fdOmitNullValues.right = new FormAttachment(100, 0);
-    wOmitNullValues.setLayoutData(fdOmitNullValues);
-    wOmitNullValues.addSelectionListener(
-        new SelectionAdapter() {
-          @Override
-          public void widgetSelected(SelectionEvent e) {
-            input.setChanged();
-          }
-        });
+  /**
+   * Puts the check line under the XPath statement. Annotations can't: the 
line follows the other
+   * options.
+   */
+  private void addXPathCheck() {
+    Control xpath = 
widgets.getWidgetsMap().get(XmlJoinMeta.WIDGET_TARGET_XPATH);
+    if (xpath == null) {
+      return;
+    }
+    Composite content = xpath.getParent();
+
+    wXPathCheck = new Composite(content, SWT.NONE);
+    PropsUi.setLook(wXPathCheck);
+    GridLayout layout = new GridLayout(2, false);
+    layout.marginWidth = 0;
+    layout.marginHeight = 0;
+    layout.horizontalSpacing = margin;
+    wXPathCheck.setLayout(layout);
+    wXPathCheckIcon = new Label(wXPathCheck, SWT.NONE);
+    PropsUi.setLook(wXPathCheckIcon);
+    wXPathCheckIcon.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, 
false));
+    wXPathCheckText = new Label(wXPathCheck, SWT.WRAP | SWT.LEFT);
+    PropsUi.setLook(wXPathCheckText);
+    GridData gdText = new GridData(SWT.FILL, SWT.TOP, true, false);
+    // Without a width the line would be measured on one line and widen the 
options
+    gdText.widthHint = (int) (CHECK_WRAP_WIDTH * 
PropsUi.getInstance().getZoomFactor());
+    wXPathCheckText.setLayoutData(gdText);
+    checkForeground = wXPathCheckText.getForeground();
+    FormData fdCheck = new FormData();
+    fdCheck.left = new FormAttachment(xpath, 0, SWT.LEFT);
+    fdCheck.right = new FormAttachment(100, 0);
+    fdCheck.top = new FormAttachment(xpath, margin);
+    wXPathCheck.setLayoutData(fdCheck);
+
+    // The rows that were under the statement go under the line now
+    for (Control control : content.getChildren()) {
+      if (control != wXPathCheck
+          && control.getLayoutData() instanceof FormData fd
+          && fd.top != null
+          && fd.top.control == xpath
+          && fd.top.alignment != SWT.CENTER) {
+        fd.top = new FormAttachment(wXPathCheck, fd.top.offset);

Review Comment:
   Everything attached below the XPath box or its label now moves under the 
check line.



##########
plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/xmljoin/XmlJoinMeta.java:
##########
@@ -55,58 +59,212 @@
     categoryDescription = "i18n::XmlJoin.category",
     keywords = "i18n::XmlJoinMeta.keyword",
     documentationUrl = "/pipeline/transforms/xmljoin.html")
+@GuiPlugin
 public class XmlJoinMeta extends BaseTransformMeta<XmlJoin, XmlJoinData> {
   private static final Class<?> PKG = XmlJoinMeta.class;
 
-  /** Flag: execute complex join */
+  public static final String GUI_PLUGIN_ELEMENT_PARENT_ID = 
"XML_JOIN_DIALOG_OPTIONS";
+
+  public static final String WIDGET_TARGET_XML_TRANSFORM = 
"XML_JOIN_TARGET_XML_TRANSFORM";
+  public static final String WIDGET_TARGET_XML_FIELD = 
"XML_JOIN_TARGET_XML_FIELD";
+  public static final String WIDGET_SOURCE_XML_TRANSFORM = 
"XML_JOIN_SOURCE_XML_TRANSFORM";
+  public static final String WIDGET_SOURCE_XML_FIELD = 
"XML_JOIN_SOURCE_XML_FIELD";
+  public static final String WIDGET_TARGET_XPATH = "XML_JOIN_TARGET_XPATH";
+  public static final String WIDGET_JOIN_MODE = "XML_JOIN_JOIN_MODE";
+  public static final String WIDGET_JOIN_COMPARE_FIELD = 
"XML_JOIN_JOIN_COMPARE_FIELD";
+  public static final String WIDGET_VALUE_XML_FIELD = 
"XML_JOIN_VALUE_XML_FIELD";
+  public static final String WIDGET_ENCODING = "XML_JOIN_ENCODING";
+  public static final String WIDGET_OMIT_XML_HEADER = 
"XML_JOIN_OMIT_XML_HEADER";
+  public static final String WIDGET_OMIT_NULL_VALUES = 
"XML_JOIN_OMIT_NULL_VALUES";
+
+  private static final String GROUP_TARGET = "i18n::XmlJoin.TargetGroup.Label";
+  private static final String GROUP_TARGET_ORDER = "100";
+  private static final String GROUP_SOURCE = "i18n::XmlJoin.SourceGroup.Label";
+  private static final String GROUP_SOURCE_ORDER = "200";
+  private static final String GROUP_JOIN = "i18n::XmlJoin.JoinGroup.Label";
+  private static final String GROUP_JOIN_ORDER = "300";
+  private static final String GROUP_RESULT = "i18n::XmlJoin.ResultGroup.Label";
+  private static final String GROUP_RESULT_ORDER = "400";
+
+  /** Flag: execute complex join. The dialog shows it as {@link 
#getJoinMode()}. */
   @HopMetadataProperty(injectionKey = "COMPLEX_JOIN")
   private boolean complexJoin;
 
   /** What transform holds the XML string to join into */
+  @GuiWidgetElement(
+      id = WIDGET_TARGET_XML_TRANSFORM,
+      order = "0110",
+      type = GuiElementType.COMBO,
+      variables = false,
+      label = "i18n::XmlJoin.TargetXMLTransform.Label",
+      toolTip = "i18n::XmlJoin.TargetXMLTransform.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_TARGET,
+      groupOrder = GROUP_TARGET_ORDER)
   @HopMetadataProperty(injectionKey = "TARGET_XML_TRANSFORM")
   private String targetXmlTransform;
 
   /** What field holds the XML string to join into */
+  @GuiWidgetElement(
+      id = WIDGET_TARGET_XML_FIELD,
+      order = "0120",
+      type = GuiElementType.COMBO,
+      label = "i18n::XmlJoin.TargetXMLField.Label",
+      toolTip = "i18n::XmlJoin.TargetXMLField.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_TARGET,
+      groupOrder = GROUP_TARGET_ORDER)
   @HopMetadataProperty(injectionKey = "TARGET_XML_FIELD")
   private String targetXmlField;
 
   /** What field holds the XML tags to join */
+  @GuiWidgetElement(
+      id = WIDGET_SOURCE_XML_FIELD,
+      order = "0220",
+      type = GuiElementType.COMBO,
+      label = "i18n::XmlJoin.SourceXMLField.Label",
+      toolTip = "i18n::XmlJoin.SourceXMLField.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_SOURCE,
+      groupOrder = GROUP_SOURCE_ORDER)
   @HopMetadataProperty(injectionKey = "SOURCE_XML_FIELD")
   private String sourceXmlField;
 
   /** The name value containing the resulting XML fragment */
+  @GuiWidgetElement(
+      id = WIDGET_VALUE_XML_FIELD,
+      order = "0410",
+      type = GuiElementType.TEXT,
+      label = "i18n::XmlJoin.ValueXMLField.Label",
+      toolTip = "i18n::XmlJoin.ValueXMLField.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_RESULT,
+      groupOrder = GROUP_RESULT_ORDER)
   @HopMetadataProperty(injectionKey = "VALUE_XML_FIELD")
   private String valueXmlField;
 
   /** The name of the repeating row XML element */
+  @GuiWidgetElement(
+      id = WIDGET_TARGET_XPATH,
+      order = "0310",
+      type = GuiElementType.TEXT,
+      label = "i18n::XmlJoin.TargetXPath.Label",
+      toolTip = "i18n::XmlJoin.TargetXPath.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_JOIN,
+      groupOrder = GROUP_JOIN_ORDER)
   @HopMetadataProperty(injectionKey = "TARGET_XPATH")
   private String targetXPath;
 
   /** What transform holds the XML strings to join */
+  @GuiWidgetElement(
+      id = WIDGET_SOURCE_XML_TRANSFORM,
+      order = "0210",
+      type = GuiElementType.COMBO,
+      variables = false,
+      label = "i18n::XmlJoin.SourceXMLTransform.Label",
+      toolTip = "i18n::XmlJoin.SourceXMLTransform.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_SOURCE,
+      groupOrder = GROUP_SOURCE_ORDER)
   @HopMetadataProperty(injectionKey = "SOURCE_XML_TRANSFORM")
   private String sourceXmlTransform;
 
   /** What field holds the join compare value */
+  @GuiWidgetElement(
+      id = WIDGET_JOIN_COMPARE_FIELD,
+      order = "0330",
+      type = GuiElementType.COMBO,
+      label = "i18n::XmlJoin.JoinCompareFiled.Label",
+      toolTip = "i18n::XmlJoin.JoinCompareField.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_JOIN,
+      groupOrder = GROUP_JOIN_ORDER)
   @HopMetadataProperty(injectionKey = "JOIN_COMPARE_FIELD")
   private String joinCompareField;
 
   /** The encoding to use for reading: null or empty string means system 
default encoding */
+  @GuiWidgetElement(
+      id = WIDGET_ENCODING,
+      order = "0420",
+      type = GuiElementType.COMBO,
+      variables = false,
+      label = "i18n::XmlJoin.Encoding.Label",
+      toolTip = "i18n::XmlJoin.Encoding.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_RESULT,
+      groupOrder = GROUP_RESULT_ORDER)
   @HopMetadataProperty(injectionKey = "ENCODING")
   private String encoding;
 
   /** Flag: execute complex join */
+  @GuiWidgetElement(
+      id = WIDGET_OMIT_XML_HEADER,
+      order = "0430",
+      type = GuiElementType.CHECKBOX,
+      label = "i18n::XmlJoin.OmitXMLHeader.Label",
+      toolTip = "i18n::XmlJoin.OmitXMLHeader.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_RESULT,
+      groupOrder = GROUP_RESULT_ORDER)
   @HopMetadataProperty(injectionKey = "OMIT_XML_HEADER")
   private boolean omitXmlHeader;
 
   /** Flag: omit null values from result xml */
+  @GuiWidgetElement(
+      id = WIDGET_OMIT_NULL_VALUES,
+      order = "0440",
+      type = GuiElementType.CHECKBOX,
+      label = "i18n::XmlJoin.OmitNullValues.Label",
+      toolTip = "i18n::XmlJoin.OmitNullValues.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_RESULT,
+      groupOrder = GROUP_RESULT_ORDER)
   @HopMetadataProperty(injectionKey = "OMIT_NULL_VALUES")
   private boolean omitNullValues;
 
+  /**
+   * Only here to put the join mode in the dialog: the widget annotations go 
on a field. It is not
+   * stored. {@link #getJoinMode()} and {@link #setJoinMode(XmlJoinMode)} read 
and write {@link
+   * #complexJoin}, which is.
+   */
+  @SuppressWarnings("unused")
+  @GuiWidgetElement(
+      id = WIDGET_JOIN_MODE,
+      order = "0305",
+      type = GuiElementType.COMBO,
+      variables = false,
+      label = "i18n::XmlJoin.JoinMode.Label",
+      toolTip = "i18n::XmlJoin.JoinMode.Tooltip",
+      parentId = GUI_PLUGIN_ELEMENT_PARENT_ID,
+      groupType = GuiWidgetGroupType.BOXES,
+      group = GROUP_JOIN,
+      groupOrder = GROUP_JOIN_ORDER)
+  private transient XmlJoinMode joinMode;

Review Comment:
   A method-level `@GuiWidgetElement` builds a button, with no getter or 
setter, and storing the mode would change the file format. So `complexJoin` is 
now the widget itself, a "Join by key" checkbox with both annotations, and 
`XmlJoinMode` is gone.



##########
plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/xmljoin/XmlJoinDialog.java:
##########
@@ -89,416 +113,540 @@ public String open() {
 
     buildButtonBar().ok(e -> ok()).cancel(e -> cancel()).build();
 
-    ModifyListener lsMod = e -> input.setChanged();
     changed = input.hasChanged();
-
-    ScrolledComposite wScrolledComposite =
-        new ScrolledComposite(shell, SWT.V_SCROLL | SWT.H_SCROLL);
-    PropsUi.setLook(wScrolledComposite);
-    FormData fdSc = new FormData();
-    fdSc.left = new FormAttachment(0, 0);
-    fdSc.top = new FormAttachment(wSpacer, 0);
-    fdSc.right = new FormAttachment(100, 0);
-    fdSc.bottom = new FormAttachment(wOk, -margin);
-    wScrolledComposite.setLayoutData(fdSc);
-    wScrolledComposite.setLayout(new FillLayout());
-    wScrolledComposite.setExpandHorizontal(true);
-    wScrolledComposite.setExpandVertical(true);
-
-    Composite wContent = new Composite(wScrolledComposite, SWT.NONE);
-    PropsUi.setLook(wContent);
-    FormLayout contentLayout = new FormLayout();
-    contentLayout.marginWidth = PropsUi.getFormMargin();
-    contentLayout.marginHeight = PropsUi.getFormMargin();
-    wContent.setLayout(contentLayout);
-
-    // Target Group
-    Group gTarget = new Group(wContent, SWT.NONE);
-    gTarget.setText(BaseMessages.getString(PKG, "XmlJoin.TargetGroup.Label"));
-    FormLayout targetLayout = new FormLayout();
-    targetLayout.marginHeight = margin;
-    targetLayout.marginWidth = margin;
-    gTarget.setLayout(targetLayout);
-    PropsUi.setLook(gTarget);
-    FormData fdTarget = new FormData();
-    fdTarget.left = new FormAttachment(0, 0);
-    fdTarget.right = new FormAttachment(100, 0);
-    fdTarget.top = new FormAttachment(wSpacer, margin);
-    gTarget.setLayoutData(fdTarget);
-    // Target XML transform line
-    Label wlTargetXMLtransform = new Label(gTarget, SWT.RIGHT);
-    wlTargetXMLtransform.setText(BaseMessages.getString(PKG, 
"XmlJoin.TargetXMLTransform.Label"));
-    PropsUi.setLook(wlTargetXMLtransform);
-    FormData fdlTargetXMLtransform = new FormData();
-    fdlTargetXMLtransform.left = new FormAttachment(0, 0);
-    fdlTargetXMLtransform.top = new FormAttachment(wSpacer, margin);
-    fdlTargetXMLtransform.right = new FormAttachment(middle, -margin);
-    wlTargetXMLtransform.setLayoutData(fdlTargetXMLtransform);
-    wTargetXmlTransform = new CCombo(gTarget, SWT.BORDER | SWT.READ_ONLY);
-    wTargetXmlTransform.setEditable(true);
-    PropsUi.setLook(wTargetXmlTransform);
-    wTargetXmlTransform.addModifyListener(lsMod);
-    FormData fdTargetXMLtransform = new FormData();
-    fdTargetXMLtransform.left = new FormAttachment(middle, 0);
-    fdTargetXMLtransform.top = new FormAttachment(wSpacer, margin);
-    fdTargetXMLtransform.right = new FormAttachment(100, 0);
-    wTargetXmlTransform.setLayoutData(fdTargetXMLtransform);
-
-    // Target XML Field line
-    Label wlTargetXMLfield = new Label(gTarget, SWT.RIGHT);
-    wlTargetXMLfield.setText(BaseMessages.getString(PKG, 
"XmlJoin.TargetXMLField.Label"));
-    PropsUi.setLook(wlTargetXMLfield);
-    FormData fdlTargetXMLfield = new FormData();
-    fdlTargetXMLfield.left = new FormAttachment(0, 0);
-    fdlTargetXMLfield.right = new FormAttachment(middle, -margin);
-    fdlTargetXMLfield.top = new FormAttachment(wTargetXmlTransform, margin);
-    wlTargetXMLfield.setLayoutData(fdlTargetXMLfield);
-
-    wTargetXmlField = new TextVar(variables, gTarget, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wTargetXmlField);
-    wTargetXmlField.addModifyListener(lsMod);
-    FormData fdTargetXMLfield = new FormData();
-    fdTargetXMLfield.left = new FormAttachment(middle, 0);
-    fdTargetXMLfield.top = new FormAttachment(wTargetXmlTransform, margin);
-    fdTargetXMLfield.right = new FormAttachment(100, -margin);
-    wTargetXmlField.setLayoutData(fdTargetXMLfield);
-
-    // Source Group
-    Group gSource = new Group(wContent, SWT.NONE);
-    gSource.setText(BaseMessages.getString(PKG, "XmlJoin.SourceGroup.Label"));
-    FormLayout sourceLayout = new FormLayout();
-    sourceLayout.marginHeight = margin;
-    sourceLayout.marginWidth = margin;
-    gSource.setLayout(sourceLayout);
-    PropsUi.setLook(gSource);
-    FormData fdSource = new FormData();
-    fdSource.left = new FormAttachment(0, 0);
-    fdSource.right = new FormAttachment(100, 0);
-    fdSource.top = new FormAttachment(gTarget, margin);
-    gSource.setLayoutData(fdSource);
-    // Source XML transform line
-    Label wlSourceXMLtransform = new Label(gSource, SWT.RIGHT);
-    wlSourceXMLtransform.setText(BaseMessages.getString(PKG, 
"XmlJoin.SourceXMLTransform.Label"));
-    PropsUi.setLook(wlSourceXMLtransform);
-    FormData fdlSourceXMLtransform = new FormData();
-    fdlSourceXMLtransform.left = new FormAttachment(0, 0);
-    fdlSourceXMLtransform.top = new FormAttachment(wTargetXmlField, margin);
-    fdlSourceXMLtransform.right = new FormAttachment(middle, -margin);
-    wlSourceXMLtransform.setLayoutData(fdlSourceXMLtransform);
-    wSourceXmlTransform = new CCombo(gSource, SWT.BORDER | SWT.READ_ONLY);
-    wSourceXmlTransform.setEditable(true);
-    PropsUi.setLook(wSourceXmlTransform);
-    wSourceXmlTransform.addModifyListener(lsMod);
-    FormData fdSourceXMLtransform = new FormData();
-    fdSourceXMLtransform.left = new FormAttachment(middle, 0);
-    fdSourceXMLtransform.top = new FormAttachment(wTargetXmlField, margin);
-    fdSourceXMLtransform.right = new FormAttachment(100, 0);
-    wSourceXmlTransform.setLayoutData(fdSourceXMLtransform);
-
-    // Source XML Field line
-    Label wlSourceXMLfield = new Label(gSource, SWT.RIGHT);
-    wlSourceXMLfield.setText(BaseMessages.getString(PKG, 
"XmlJoin.SourceXMLField.Label"));
-    PropsUi.setLook(wlSourceXMLfield);
-    FormData fdlSourceXMLfield = new FormData();
-    fdlSourceXMLfield.left = new FormAttachment(0, 0);
-    fdlSourceXMLfield.right = new FormAttachment(middle, -margin);
-    fdlSourceXMLfield.top = new FormAttachment(wSourceXmlTransform, margin);
-    wlSourceXMLfield.setLayoutData(fdlSourceXMLfield);
-
-    wSourceXmlField = new TextVar(variables, gSource, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wSourceXmlField);
-    wSourceXmlField.addModifyListener(lsMod);
-    FormData fdSourceXMLfield = new FormData();
-    fdSourceXMLfield.left = new FormAttachment(middle, 0);
-    fdSourceXMLfield.top = new FormAttachment(wSourceXmlTransform, margin);
-    fdSourceXMLfield.right = new FormAttachment(100, -margin);
-    wSourceXmlField.setLayoutData(fdSourceXMLfield);
-
-    // Join Group
-    Group gJoin = new Group(wContent, SWT.NONE);
-    gJoin.setText(BaseMessages.getString(PKG, "XmlJoin.JoinGroup.Label"));
-    FormLayout joinLayout = new FormLayout();
-    joinLayout.marginHeight = margin;
-    joinLayout.marginWidth = margin;
-    gJoin.setLayout(joinLayout);
-    PropsUi.setLook(gJoin);
-    FormData fdJoin = new FormData();
-    fdJoin.left = new FormAttachment(0, 0);
-    fdJoin.right = new FormAttachment(100, 0);
-    fdJoin.top = new FormAttachment(gSource, margin);
-    gJoin.setLayoutData(fdJoin);
-
-    // Target XPath line
-    Label wlTargetXPath = new Label(gJoin, SWT.RIGHT);
-    wlTargetXPath.setText(BaseMessages.getString(PKG, 
"XmlJoin.TargetXPath.Label"));
-    PropsUi.setLook(wlTargetXPath);
-    FormData fdlTargetXPath = new FormData();
-    fdlTargetXPath.left = new FormAttachment(0, 0);
-    fdlTargetXPath.right = new FormAttachment(middle, -margin);
-    fdlTargetXPath.top = new FormAttachment(wSourceXmlField, margin);
-    wlTargetXPath.setLayoutData(fdlTargetXPath);
-
-    wTargetXPath = new TextVar(variables, gJoin, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wTargetXPath);
-    wTargetXPath.addModifyListener(lsMod);
-    FormData fdTargetXPath = new FormData();
-    fdTargetXPath.left = new FormAttachment(middle, 0);
-    fdTargetXPath.top = new FormAttachment(wSourceXmlField, margin);
-    fdTargetXPath.right = new FormAttachment(100, -margin);
-    wTargetXPath.setLayoutData(fdTargetXPath);
-
-    // Complex Join Line
-    Label wlComplexJoin = new Label(gJoin, SWT.RIGHT);
-    wlComplexJoin.setText(BaseMessages.getString(PKG, 
"XmlJoin.ComplexJoin.Label"));
-    PropsUi.setLook(wlComplexJoin);
-    FormData fdlComplexJoin = new FormData();
-    fdlComplexJoin.left = new FormAttachment(0, 0);
-    fdlComplexJoin.top = new FormAttachment(wTargetXPath, margin);
-    fdlComplexJoin.right = new FormAttachment(middle, -margin);
-    wlComplexJoin.setLayoutData(fdlComplexJoin);
-    wComplexJoin = new Button(gJoin, SWT.CHECK);
-    PropsUi.setLook(wComplexJoin);
-    FormData fdComplexJoin = new FormData();
-    fdComplexJoin.left = new FormAttachment(middle, 0);
-    fdComplexJoin.top = new FormAttachment(wlComplexJoin, 0, SWT.CENTER);
-    fdComplexJoin.right = new FormAttachment(100, 0);
-    wComplexJoin.setLayoutData(fdComplexJoin);
-    wComplexJoin.addSelectionListener(
-        new SelectionAdapter() {
+    loading = true;
+
+    Label wIntro = new Label(shell, SWT.WRAP | SWT.LEFT);
+    wIntro.setText(BaseMessages.getString(PKG, "XmlJoin.Intro"));
+    PropsUi.setLook(wIntro);
+    FormData fdIntro = new FormData();
+    fdIntro.left = new FormAttachment(0, 0);
+    fdIntro.right = new FormAttachment(100, 0);
+    fdIntro.top = new FormAttachment(wSpacer, margin);
+    wIntro.setLayoutData(fdIntro);
+
+    // The options on the left, the target document on the right
+    SashForm sash = new SashForm(shell, SWT.HORIZONTAL);
+    PropsUi.setLook(sash);
+    FormData fdSash = new FormData();
+    fdSash.left = new FormAttachment(0, 0);
+    fdSash.right = new FormAttachment(100, 0);
+    fdSash.top = new FormAttachment(wIntro, margin);
+    fdSash.bottom = new FormAttachment(wOk, -2 * margin);
+    sash.setLayoutData(fdSash);
+    Composite options = new Composite(sash, SWT.NONE);
+    PropsUi.setLook(options);
+    options.setLayout(new FormLayout());
+    widgets =
+        GuiCompositeWidgets.addScrolledComposite(
+            options, variables, null, null, 
XmlJoinMeta.GUI_PLUGIN_ELEMENT_PARENT_ID, input);
+    wDocument = new TargetDocumentPane(sash, this::loadDocument);
+    wDocument.setPickListener(this::picked);
+    wDocument.setKeyNames(this::keyNames);
+    sash.setWeights(new int[] {60, 40});
+    widgets.setWidgetsListener(
+        new GuiCompositeWidgetsAdapter() {
           @Override
-          public void widgetSelected(SelectionEvent e) {
+          public void widgetModified(
+              GuiCompositeWidgets compositeWidgets, Control changedWidget, 
String widgetId) {
+            if (loading) {
+              return;
+            }
             input.setChanged();
-
-            if (wComplexJoin.getSelection()) {
-              wJoinCompareField.setEnabled(true);
-            } else {
-              wJoinCompareField.setEnabled(false);
+            switch (widgetId) {
+              case XmlJoinMeta.WIDGET_JOIN_MODE -> joinModeChanged();
+              case XmlJoinMeta.WIDGET_TARGET_XPATH -> 
wDocument.show(resolvedXPath());
+              case XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM -> {
+                fillOtherInput(XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM);
+                wDocument.setDocument(null, null);
+              }
+              case XmlJoinMeta.WIDGET_TARGET_XML_FIELD -> 
wDocument.setDocument(null, null);
+              case XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM ->
+                  fillOtherInput(XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM);
+              default -> {
+                // Nothing else depends on another option
+              }
             }
+            updateXPathCheck();
           }
         });
 
-    // Join Compare field line
-    Label wlJoinCompareField = new Label(gJoin, SWT.RIGHT);
-    wlJoinCompareField.setText(BaseMessages.getString(PKG, 
"XmlJoin.JoinCompareFiled.Label"));
-    PropsUi.setLook(wlJoinCompareField);
-    FormData fdlJoinCompareField = new FormData();
-    fdlJoinCompareField.left = new FormAttachment(0, 0);
-    fdlJoinCompareField.right = new FormAttachment(middle, -margin);
-    fdlJoinCompareField.top = new FormAttachment(wComplexJoin, margin);
-    wlJoinCompareField.setLayoutData(fdlJoinCompareField);
-
-    wJoinCompareField = new TextVar(variables, gJoin, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wJoinCompareField);
-    wJoinCompareField.addModifyListener(lsMod);
-    FormData fdJoinCompareField = new FormData();
-    fdJoinCompareField.left = new FormAttachment(middle, 0);
-    fdJoinCompareField.top = new FormAttachment(wComplexJoin, margin);
-    fdJoinCompareField.right = new FormAttachment(100, -margin);
-    wJoinCompareField.setLayoutData(fdJoinCompareField);
-    wJoinCompareField.setEnabled(false);
-
-    // Result Group
-    Group gResult = new Group(wContent, SWT.NONE);
-    gResult.setText(BaseMessages.getString(PKG, "XmlJoin.ResultGroup.Label"));
-    FormLayout resultLayout = new FormLayout();
-    resultLayout.marginHeight = margin;
-    resultLayout.marginWidth = margin;
-    gResult.setLayout(resultLayout);
-    PropsUi.setLook(gResult);
-    FormData fdResult = new FormData();
-    fdResult.left = new FormAttachment(0, 0);
-    fdResult.right = new FormAttachment(100, 0);
-    fdResult.top = new FormAttachment(gJoin, margin);
-    fdResult.bottom = new FormAttachment(100, -50);
-    gResult.setLayoutData(fdResult);
-
-    // Value XML Field line
-    Label wlValueXmlField = new Label(gResult, SWT.RIGHT);
-    wlValueXmlField.setText(BaseMessages.getString(PKG, 
"XmlJoin.ValueXMLField.Label"));
-    PropsUi.setLook(wlValueXmlField);
-    FormData fdlValueXmlField = new FormData();
-    fdlValueXmlField.left = new FormAttachment(0, 0);
-    fdlValueXmlField.right = new FormAttachment(middle, -margin);
-    fdlValueXmlField.top = new FormAttachment(wJoinCompareField, margin);
-    wlValueXmlField.setLayoutData(fdlValueXmlField);
-    wValueXmlField = new TextVar(variables, gResult, SWT.SINGLE | SWT.LEFT | 
SWT.BORDER);
-    PropsUi.setLook(wValueXmlField);
-    wValueXmlField.addModifyListener(lsMod);
-    FormData fdValueXMLfield = new FormData();
-    fdValueXMLfield.left = new FormAttachment(middle, 0);
-    fdValueXMLfield.top = new FormAttachment(wJoinCompareField, margin);
-    fdValueXMLfield.right = new FormAttachment(100, -margin);
-    wValueXmlField.setLayoutData(fdValueXMLfield);
-
-    // Encoding Line
-    Label wlEncoding = new Label(gResult, SWT.RIGHT);
-    wlEncoding.setText(BaseMessages.getString(PKG, "XmlJoin.Encoding.Label"));
-    PropsUi.setLook(wlEncoding);
-    FormData fdlEncoding = new FormData();
-    fdlEncoding.left = new FormAttachment(0, 0);
-    fdlEncoding.top = new FormAttachment(wValueXmlField, margin);
-    fdlEncoding.right = new FormAttachment(middle, -margin);
-    wlEncoding.setLayoutData(fdlEncoding);
-    wEncoding = new CCombo(gResult, SWT.BORDER | SWT.READ_ONLY);
-    wEncoding.setEditable(true);
-    PropsUi.setLook(wEncoding);
-    wEncoding.addModifyListener(lsMod);
-    FormData fdEncoding = new FormData();
-    fdEncoding.left = new FormAttachment(middle, 0);
-    fdEncoding.top = new FormAttachment(wValueXmlField, margin);
-    fdEncoding.right = new FormAttachment(100, 0);
-    wEncoding.setLayoutData(fdEncoding);
-    wEncoding.addFocusListener(
-        new FocusListener() {
-          @Override
-          public void focusLost(FocusEvent e) {
-            // Do nothing
-          }
+    inputTransforms =
+        pipelineMeta
+            .findPreviousTransforms(pipelineMeta.findTransform(transformName), 
true)
+            .stream()
+            .map(TransformMeta::getName)
+            .toArray(String[]::new);
+    setComboItems(XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM, inputTransforms);
+    setComboItems(XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM, inputTransforms);
+    setComboItems(XmlJoinMeta.WIDGET_ENCODING, ConstUi.getEncodings());
+    listFieldsOnFocus(XmlJoinMeta.WIDGET_TARGET_XML_FIELD, 
XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM);
+    listFieldsOnFocus(XmlJoinMeta.WIDGET_SOURCE_XML_FIELD, 
XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM);
+    listFieldsOnFocus(
+        XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD, 
XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM);
+    addXPathCheck();
+    enableKeyField();
+    wDocument.setByKey(joinMode() == XmlJoinMode.BY_KEY);
+    wDocument.show(resolvedXPath());
+    updateXPathCheck();
+
+    loading = false;
+    input.setChanged(changed);
 
-          @Override
-          public void focusGained(FocusEvent e) {
-            Cursor busy = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
-            shell.setCursor(busy);
-            setEncodings();
-            shell.setCursor(null);
-            busy.dispose();
-          }
-        });
+    focusTransformName();
+    BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());
 
-    // Complex Join Line
-    Label wlOmitXMLHeader = new Label(gResult, SWT.RIGHT);
-    wlOmitXMLHeader.setText(BaseMessages.getString(PKG, 
"XmlJoin.OmitXMLHeader.Label"));
-    PropsUi.setLook(wlOmitXMLHeader);
-    FormData fdlOmitXMLHeader = new FormData();
-    fdlOmitXMLHeader.left = new FormAttachment(0, 0);
-    fdlOmitXMLHeader.top = new FormAttachment(wEncoding, margin);
-    fdlOmitXMLHeader.right = new FormAttachment(middle, -margin);
-    wlOmitXMLHeader.setLayoutData(fdlOmitXMLHeader);
-    wOmitXmlHeader = new Button(gResult, SWT.CHECK);
-    PropsUi.setLook(wOmitXmlHeader);
-    FormData fdOmitXMLHeader = new FormData();
-    fdOmitXMLHeader.left = new FormAttachment(middle, 0);
-    fdOmitXMLHeader.top = new FormAttachment(wlOmitXMLHeader, 0, SWT.CENTER);
-    fdOmitXMLHeader.right = new FormAttachment(100, 0);
-    wOmitXmlHeader.setLayoutData(fdOmitXMLHeader);
-    wOmitXmlHeader.addSelectionListener(
-        new SelectionAdapter() {
-          @Override
-          public void widgetSelected(SelectionEvent e) {
-            input.setChanged();
-          }
-        });
+    return transformName;
+  }
 
-    Label wlOmitNullValues = new Label(gResult, SWT.RIGHT);
-    wlOmitNullValues.setText(BaseMessages.getString(PKG, 
"XmlJoin.OmitNullValues.Label"));
-    PropsUi.setLook(wlOmitNullValues);
-    FormData fdlOmitNullValues = new FormData();
-    fdlOmitNullValues.left = new FormAttachment(0, 0);
-    fdlOmitNullValues.top = new FormAttachment(wOmitXmlHeader, margin);
-    fdlOmitNullValues.right = new FormAttachment(middle, -margin);
-    wlOmitNullValues.setLayoutData(fdlOmitNullValues);
-    wOmitNullValues = new Button(gResult, SWT.CHECK);
-    PropsUi.setLook(wOmitNullValues);
-    FormData fdOmitNullValues = new FormData();
-    fdOmitNullValues.left = new FormAttachment(middle, 0);
-    fdOmitNullValues.top = new FormAttachment(wlOmitNullValues, 0, SWT.CENTER);
-    fdOmitNullValues.right = new FormAttachment(100, 0);
-    wOmitNullValues.setLayoutData(fdOmitNullValues);
-    wOmitNullValues.addSelectionListener(
-        new SelectionAdapter() {
-          @Override
-          public void widgetSelected(SelectionEvent e) {
-            input.setChanged();
-          }
-        });
+  /**
+   * Puts the check line under the XPath statement. Annotations can't: the 
line follows the other
+   * options.
+   */
+  private void addXPathCheck() {
+    Control xpath = 
widgets.getWidgetsMap().get(XmlJoinMeta.WIDGET_TARGET_XPATH);
+    if (xpath == null) {
+      return;
+    }
+    Composite content = xpath.getParent();
+
+    wXPathCheck = new Composite(content, SWT.NONE);
+    PropsUi.setLook(wXPathCheck);
+    GridLayout layout = new GridLayout(2, false);
+    layout.marginWidth = 0;
+    layout.marginHeight = 0;
+    layout.horizontalSpacing = margin;
+    wXPathCheck.setLayout(layout);
+    wXPathCheckIcon = new Label(wXPathCheck, SWT.NONE);
+    PropsUi.setLook(wXPathCheckIcon);
+    wXPathCheckIcon.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, false, 
false));
+    wXPathCheckText = new Label(wXPathCheck, SWT.WRAP | SWT.LEFT);
+    PropsUi.setLook(wXPathCheckText);
+    GridData gdText = new GridData(SWT.FILL, SWT.TOP, true, false);
+    // Without a width the line would be measured on one line and widen the 
options
+    gdText.widthHint = (int) (CHECK_WRAP_WIDTH * 
PropsUi.getInstance().getZoomFactor());
+    wXPathCheckText.setLayoutData(gdText);
+    checkForeground = wXPathCheckText.getForeground();
+    FormData fdCheck = new FormData();
+    fdCheck.left = new FormAttachment(xpath, 0, SWT.LEFT);
+    fdCheck.right = new FormAttachment(100, 0);
+    fdCheck.top = new FormAttachment(xpath, margin);
+    wXPathCheck.setLayoutData(fdCheck);
+
+    // The rows that were under the statement go under the line now
+    for (Control control : content.getChildren()) {
+      if (control != wXPathCheck
+          && control.getLayoutData() instanceof FormData fd
+          && fd.top != null
+          && fd.top.control == xpath
+          && fd.top.alignment != SWT.CENTER) {
+        fd.top = new FormAttachment(wXPathCheck, fd.top.offset);
+      }
+    }
+    GuiCompositeWidgets.updateScrolledMinSize(content);
+  }
 
-    shell.layout();
+  /**
+   * Says what the statement finds in the target document: the node the 
elements go under, no node,
+   * or why it is not valid XPath. Without a document, or when something else 
is missing, it says
+   * that instead.
+   */
+  private void updateXPathCheck() {
+    if (wXPathCheck == null || wXPathCheck.isDisposed()) {
+      return;
+    }
+    GuiResource resource = GuiResource.getInstance();
+    String xpath = Const.NVL(resolvedXPath(), "").trim();
+    String keyField = 
variables.resolve(textOf(XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD));
+    boolean byKey = joinMode() == XmlJoinMode.BY_KEY;
+    boolean hasPlaceholder = 
xpath.contains(TargetXPathBuilder.KEY_PLACEHOLDER);
+    TargetDocumentPane.Check check = wDocument.check();
+
+    Image icon = resource.getImageInfo();
+    Color color = checkForeground;
+    String text;
+    String toolTip = null;
+    if (xpath.isEmpty()) {
+      text = message("XmlJoin.XPathHint.Empty");
+    } else if (byKey && TargetXPathBuilder.KEY_PLACEHOLDER.equals(xpath)) {
+      text = message("XmlJoin.XPathHint.FromKeyField");
+    } else if (check.outcome() == TargetDocumentPane.Outcome.INVALID) {
+      icon = resource.getImageError();
+      color = resource.getColorRed();
+      text = message("XmlJoin.XPathHint.Invalid", check.error());
+    } else if (check.outcome() == TargetDocumentPane.Outcome.NOT_FOUND) {
+      icon = resource.getImageError();
+      color = resource.getColorRed();
+      text =
+          message(
+              byKey && hasPlaceholder
+                  ? "XmlJoin.XPathHint.NotFound.ByKey"
+                  : "XmlJoin.XPathHint.NotFound");
+    } else if (check.outcome() == 
TargetDocumentPane.Outcome.KEY_FINDS_NO_NODE) {
+      icon = resource.getImageError();
+      color = resource.getColorRed();
+      text = message("XmlJoin.XPathHint.KeyFindsNoNode", check.keyValue());
+    } else if (check.outcome() == TargetDocumentPane.Outcome.KEY_NOT_UNIQUE) {
+      icon = resource.getImageWarning();
+      text = message("XmlJoin.XPathHint.KeyNotUnique", check.keyValue(), 
location(check));
+      toolTip =
+          message(
+              "XmlJoin.XPathHint.Example",
+              check.keyValue(),
+              TargetXPathBuilder.forKeyValue(xpath, check.keyValue()));
+    } else if (check.outcome() == TargetDocumentPane.Outcome.NOT_FOLLOWED) {
+      text = message("XmlJoin.XPathHint.NotFollowed");
+    } else if (byKey && !hasPlaceholder) {
+      icon = resource.getImageWarning();
+      text = message("XmlJoin.XPathHint.NoPlaceholder");
+    } else if (byKey && Utils.isEmpty(keyField)) {
+      icon = resource.getImageWarning();
+      text = message("XmlJoin.XPathHint.ByKeyNoField");
+    } else if (check.outcome() == TargetDocumentPane.Outcome.FOUND
+        || check.outcome() == TargetDocumentPane.Outcome.FOUND_NOT_LISTED) {
+      icon = resource.getImageSuccess();
+      color = resource.getColorDarkGreen();
+      text = found(check, byKey);
+      if (byKey && check.keyValue() != null) {
+        toolTip =
+            message(
+                "XmlJoin.XPathHint.Example",
+                check.keyValue(),
+                TargetXPathBuilder.forKeyValue(xpath, check.keyValue()));
+      }
+    } else if (byKey) {
+      text = message("XmlJoin.XPathHint.NotChecked.ByKey", keyField);
+    } else {
+      text = message("XmlJoin.XPathHint.NotChecked");
+    }
 
-    wScrolledComposite.setContent(wContent);
-    wContent.pack();
-    wScrolledComposite.setMinSize(wContent.computeSize(SWT.DEFAULT, 
SWT.DEFAULT));
+    int heightBefore = wXPathCheck.getSize().y;
+    wXPathCheckIcon.setImage(icon);
+    wXPathCheckText.setText(text);
+    wXPathCheckText.setForeground(color);
+    wXPathCheckText.setToolTipText(toolTip == null ? text : text + Const.CR + 
toolTip);
+    int width = wXPathCheck.getSize().x;
+    if (width > 0 && wXPathCheck.computeSize(width, SWT.DEFAULT, true).y == 
heightBefore) {
+      wXPathCheck.layout(true, true);
+    } else {
+      relayoutOptions();
+    }
+  }
 
-    getData();
-    input.setChanged(changed);
+  /**
+   * The check line got more or fewer lines: its box grows or shrinks, the 
options under it move,
+   * and the height they scroll over changes. The width stays: measured again, 
the options would be
+   * as wide as the statement typed in them.
+   */
+  private void relayoutOptions() {
+    // The line sits in a scrolled box, and the boxes in the scrolled options: 
from the inside out,
+    // each one gets the height of what it holds now
+    for (Control control = wXPathCheck;
+        control != null && !(control instanceof Shell);
+        control = control.getParent()) {
+      if (control instanceof ScrolledComposite scrolled
+          && scrolled.getContent() instanceof Composite content) {
+        content.layout(true, true);
+        int width = Math.max(scrolled.getClientArea().width, 
scrolled.getMinWidth());
+        scrolled.setMinHeight(content.computeSize(width, SWT.DEFAULT, true).y);
+      }
+    }
+  }
 
-    List<TransformMeta> transforms =
-        
pipelineMeta.findPreviousTransforms(pipelineMeta.findTransform(transformName), 
true);
-    for (TransformMeta transformMeta : transforms) {
-      wTargetXmlTransform.add(transformMeta.getName());
-      wSourceXmlTransform.add(transformMeta.getName());
+  /**
+   * The node the elements go under, highlighted in the target document or 
past the listed nodes.
+   */
+  private static String found(TargetDocumentPane.Check check, boolean byKey) {
+    String node = location(check);
+    String where;
+    if (!byKey) {
+      where = message("XmlJoin.XPathHint.Found", node);
+    } else {
+      where =
+          (check.keyValue() != null
+                  ? message("XmlJoin.XPathHint.Found.ByKey", check.keyValue(), 
node)
+                  : message("XmlJoin.XPathHint.Found.ByKeyNoValue", node))
+              + " "
+              + (check.keyNodes() == 1
+                  ? message("XmlJoin.XPathHint.KeyNodes.One")
+                  : message("XmlJoin.XPathHint.KeyNodes.Many", 
check.keyNodes()));
     }
-    focusTransformName();
-    BaseDialog.defaultShellHandling(shell, c -> ok(), c -> cancel());
+    String shown =
+        check.outcome() == TargetDocumentPane.Outcome.FOUND
+            ? message("XmlJoin.XPathHint.Highlighted")
+            : message("XmlJoin.XPathHint.NotListed", 
TargetDocumentPane.MAX_CHILDREN);
+    return where + " " + shown;
+  }
 
-    return transformName;
+  /** The node of a check and its parent, or that it is the root. */
+  private static String location(TargetDocumentPane.Check check) {
+    return check.parent() == null
+        ? message("XmlJoin.XPathHint.Node.Root", check.node())
+        : message("XmlJoin.XPathHint.Node.InParent", check.node(), 
check.parent());
   }
 
-  public void setMinimalWidth() {
-    // TODO - implement when necessary
+  private static String message(String key, Object... arguments) {
+    return BaseMessages.getString(PKG, key, arguments);
   }
 
-  /** Copy information from the meta-data input to the dialog fields. */
-  public void getData() {
-    logDebug(BaseMessages.getString(PKG, 
"AddXMLDialog.Log.GettingFieldsInfo"));
+  /** Shows the first document of the target transform beside the options. */
+  private void loadDocument() {
+    String targetTransform = textOf(XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM);
+    String targetField = 
variables.resolve(textOf(XmlJoinMeta.WIDGET_TARGET_XML_FIELD));
+    if (Utils.isEmpty(targetTransform) || Utils.isEmpty(targetField)) {
+      MessageBox box = new MessageBox(shell, SWT.OK | SWT.ICON_INFORMATION);
+      box.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Title"));
+      box.setMessage(BaseMessages.getString(PKG, 
"XmlJoin.Document.ChooseTarget"));
+      box.open();
+      return;
+    }
+    Document document;
+    try {
+      document = firstTargetDocument(targetTransform, targetField);
+    } catch (HopException e) {
+      new ErrorDialog(
+          shell,
+          BaseMessages.getString(PKG, "XmlJoin.Document.Title"),
+          BaseMessages.getString(PKG, "XmlJoin.Document.Error", 
targetTransform),
+          e);
+      return;
+    }
+    if (document != null) {
+      wDocument.setDocument(document, targetTransform);
+      updateXPathCheck();
+    }
+  }
 
-    wTargetXmlTransform.setText(Const.NVL(input.getTargetXmlTransform(), ""));
-    wTargetXmlField.setText(Const.NVL(input.getTargetXmlField(), ""));
-    wSourceXmlTransform.setText(Const.NVL(input.getSourceXmlTransform(), ""));
-    wSourceXmlField.setText(Const.NVL(input.getSourceXmlField(), ""));
-    wValueXmlField.setText(Const.NVL(input.getValueXmlField(), ""));
-    wTargetXPath.setText(Const.NVL(input.getTargetXPath(), ""));
-    wEncoding.setText(Const.NVL(input.getEncoding(), ""));
-    wJoinCompareField.setText(Const.NVL(input.getJoinCompareField(), ""));
+  /**
+   * A node was clicked in the document: its statement goes in the XPath 
statement. When the key
+   * field is empty and a source field has the name of the chosen key, that 
field becomes the key
+   * field.
+   */
+  private void picked(String xpath, KeyCandidate key) {
+    if (key != null && 
Utils.isEmpty(textOf(XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD))) {
+      String localName = key.name().substring(key.name().indexOf(':') + 1);
+      for (String field : fieldsOf(XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM)) {
+        if (field.equalsIgnoreCase(localName)) {
+          setText(XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD, field);
+          break;
+        }
+      }
+    }
+    writtenXPath = xpath;
+    setText(XmlJoinMeta.WIDGET_TARGET_XPATH, xpath);
+    updateXPathCheck();
+  }
 
-    wComplexJoin.setSelection(input.isComplexJoin());
-    wOmitXmlHeader.setSelection(input.isOmitXmlHeader());
-    wOmitNullValues.setSelection(input.isOmitNullValues());
+  /** The names to choose a key by: the key field, or else the fields of the 
source transform. */
+  private List<String> keyNames() {
+    String keyField = 
variables.resolve(textOf(XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD));
+    return Utils.isEmpty(keyField)
+        ? List.of(fieldsOf(XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM))
+        : List.of(keyField);
+  }
 
-    wJoinCompareField.setEnabled(input.isComplexJoin());
+  /**
+   * The key field and the key in the document only mean something under the 
node of their key. A
+   * statement the document wrote is written again for the new mode; one typed 
by hand stays.
+   */
+  private void joinModeChanged() {
+    enableKeyField();
+    boolean written = writtenXPath != null && 
writtenXPath.equals(resolvedXPath());
+    wDocument.setByKey(joinMode() == XmlJoinMode.BY_KEY);
+    if (written) {
+      wDocument.pickAgain();
+    } else {
+      wDocument.show(resolvedXPath());
+    }
   }
 
-  private void cancel() {
-    transformName = null;
+  private String resolvedXPath() {
+    return variables.resolve(textOf(XmlJoinMeta.WIDGET_TARGET_XPATH));
+  }
 
-    input.setChanged(backupChanged);
+  /**
+   * The XML document in the first row of the target transform. Only that 
transform and the
+   * transforms that lead to it are run, in preview. Null when the preview was 
cancelled or sent no
+   * rows; the preview log is shown in that last case.
+   */
+  Document firstTargetDocument(String targetTransform, String targetField) 
throws HopException {
+    PipelineMeta upstream = UpstreamPipeline.of(pipelineMeta, variables, 
targetTransform);
+    PipelinePreviewProgressDialog progress =
+        new PipelinePreviewProgressDialog(
+            shell, variables, upstream, new String[] {targetTransform}, new 
int[] {1});
+    try {
+      progress.open();
+    } finally {
+      // In Hop Web the preview runs without a progress window, puts a busy 
cursor on this shell
+      // and leaves it there
+      shell.setCursor(null);
+    }
+    if (progress.isCancelled() || progress.getLoggingText() == null) {
+      // Cancelled, or the preview could not start: it has already said why
+      return null;
+    }
+    List<Object[]> rows = progress.getPreviewRows(targetTransform);
+    IRowMeta rowMeta = progress.getPreviewRowsMeta(targetTransform);
+    if (rows == null || rows.isEmpty() || rowMeta == null) {
+      EnterTextDialog log =
+          new EnterTextDialog(
+              shell,
+              BaseMessages.getString(PKG, "XmlJoin.Document.Title"),
+              BaseMessages.getString(PKG, "XmlJoin.Document.NoRows", 
targetTransform),
+              Const.NVL(progress.getLoggingText(), ""),
+              true);
+      log.setReadOnly();
+      log.open();
+      return null;
+    }
+    return UpstreamPipeline.documentIn(rowMeta, rows.get(0), targetTransform, 
targetField);
+  }
 
-    dispose();
+  /**
+   * Lists the fields of the transform chosen in another combo when the field 
combo gets focus.
+   * Looking them up when the dialog opens would make it wait for whatever the 
upstream transforms
+   * need to describe their fields, a database query for instance.
+   */
+  private void listFieldsOnFocus(String fieldWidgetId, String 
transformWidgetId) {
+    Control control = widgets.getWidgetsMap().get(fieldWidgetId);
+    if (control instanceof ComboVar comboVar) {
+      comboVar
+          .getCComboWidget()
+          .addListener(SWT.FocusIn, e -> setComboItems(fieldWidgetId, 
fieldsOf(transformWidgetId)));
+    }
+  }
+
+  /** The output fields of the transform selected in the given combo, none if 
it is unknown. */
+  private String[] fieldsOf(String transformWidgetId) {
+    String name = textOf(transformWidgetId);
+    if (Utils.isEmpty(name)) {
+      return new String[0];
+    }
+    try {
+      IRowMeta fields = pipelineMeta.getTransformFields(variables, name);
+      return fields == null ? new String[0] : fields.getFieldNames();
+    } catch (HopException e) {
+      logError(BaseMessages.getString(PKG, "XmlJoin.Log.UnableToGetFields", 
name), e);
+      return new String[0];
+    }
   }
 
-  private void getInfo(XmlJoinMeta tfoi) {
-    tfoi.setTargetXmlTransform(wTargetXmlTransform.getText());
-    tfoi.setTargetXmlField(wTargetXmlField.getText());
-    tfoi.setSourceXmlTransform(wSourceXmlTransform.getText());
-    tfoi.setSourceXmlField(wSourceXmlField.getText());
-    tfoi.setValueXmlField(wValueXmlField.getText());
-    tfoi.setTargetXPath(wTargetXPath.getText());
-    tfoi.setJoinCompareField(wJoinCompareField.getText());
-    tfoi.setComplexJoin(wComplexJoin.getSelection());
-    tfoi.setEncoding(wEncoding.getText());
-    tfoi.setOmitXmlHeader(wOmitXmlHeader.getSelection());
-    tfoi.setOmitNullValues(wOmitNullValues.getSelection());
+  private XmlJoinMode joinMode() {
+    return IEnumHasCodeAndDescription.lookupDescription(
+        XmlJoinMode.class, textOf(XmlJoinMeta.WIDGET_JOIN_MODE), 
XmlJoinMode.ONE_NODE);
   }
 
-  private void ok() {
-    if (Utils.isEmpty(wTransformName.getText())) {
+  /** The key field only means something when elements go under the node of 
their key. */
+  private void enableKeyField() {
+    Control keyField = 
widgets.getWidgetsMap().get(XmlJoinMeta.WIDGET_JOIN_COMPARE_FIELD);
+    if (keyField != null) {
+      keyField.setEnabled(joinMode() == XmlJoinMode.BY_KEY);
+    }
+  }
+
+  /**
+   * With exactly two transforms sending rows to the join, picking one of them 
as the target (or
+   * source) leaves only the other for the empty source (or target) box.
+   */
+  private void fillOtherInput(String changedWidgetId) {
+    String otherWidgetId =
+        XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM.equals(changedWidgetId)
+            ? XmlJoinMeta.WIDGET_SOURCE_XML_TRANSFORM
+            : XmlJoinMeta.WIDGET_TARGET_XML_TRANSFORM;
+    if (inputTransforms.length != 2 || !Utils.isEmpty(textOf(otherWidgetId))) {
       return;
     }
+    String chosen = textOf(changedWidgetId);
+    String other = null;
+    if (inputTransforms[0].equals(chosen)) {
+      other = inputTransforms[1];
+    } else if (inputTransforms[1].equals(chosen)) {
+      other = inputTransforms[0];
+    }
+    if (other != null) {
+      setText(otherWidgetId, other);
+    }
+  }
 
-    transformName = wTransformName.getText(); // return value
+  private String textOf(String widgetId) {
+    Control control = widgets.getWidgetsMap().get(widgetId);
+    if (control instanceof ComboVar comboVar) {
+      return comboVar.getText();
+    } else if (control instanceof Combo combo) {
+      return combo.getText();
+    } else if (control instanceof TextVar textVar) {
+      return textVar.getText();
+    } else if (control instanceof Text text) {
+      return text.getText();
+    }
+    return null;
+  }
 
-    getInfo(input);
+  private void setText(String widgetId, String value) {
+    Control control = widgets.getWidgetsMap().get(widgetId);
+    if (control instanceof ComboVar comboVar) {
+      comboVar.setText(value);
+    } else if (control instanceof Combo combo) {
+      combo.setText(value);
+    } else if (control instanceof TextVar textVar) {
+      textVar.setText(value);
+    } else if (control instanceof Text text) {
+      text.setText(value);
+    }
+  }
 
-    dispose();
+  /** Replaces the items of a combo and keeps what it shows. */
+  private void setComboItems(String widgetId, String[] items) {
+    Control control = widgets.getWidgetsMap().get(widgetId);
+    if (control == null || control.isDisposed()) {
+      return;
+    }
+    boolean wasLoading = loading;
+    loading = true;
+    try {
+      if (control instanceof ComboVar comboVar) {
+        String text = comboVar.getText();
+        comboVar.setItems(items);
+        comboVar.setText(text);
+      } else if (control instanceof Combo combo) {
+        String text = combo.getText();
+        combo.setItems(items);
+        combo.setText(text);
+      }
+    } finally {
+      loading = wasLoading;
+    }
   }
 
-  private void setEncodings() {
-    // Encoding of the text file:
-    if (!gotEncodings) {
-      gotEncodings = true;
+  private void cancel() {
+    transformName = null;
+    input.setChanged(backupChanged);
+    dispose();
+  }
 
-      String encoding = wEncoding.getText();
-      wEncoding.setItems(ConstUi.getEncodings());
-      wEncoding.setText(Const.NVL(encoding, ""));
+  private void ok() {
+    if (Utils.isEmpty(wTransformName.getText())) {
+      return;
     }
+    transformName = wTransformName.getText();
+    widgets.getWidgetsContents(input, 
XmlJoinMeta.GUI_PLUGIN_ELEMENT_PARENT_ID);
+    storeEmptyOptionsAsEmptyStrings();
+    dispose();
+  }
+
+  /**
+   * The widgets leave an option that was never set at null. This dialog has 
always stored an empty
+   * string instead: the transform then reports a missing field by name rather 
than failing on a
+   * null, and saved pipelines keep the empty tags they had.
+   */
+  private void storeEmptyOptionsAsEmptyStrings() {

Review Comment:
   Removed. XmlJoin reports an empty or null target field, source field, XPath 
or key field by name, at the point where it used them before. Covered by 
`XmlJoinEmptyOptionsTest`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to