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


##########
plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/xmljoin/UpstreamPipeline.java:
##########
@@ -0,0 +1,152 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.xml.xmljoin;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.HashSet;
+import java.util.Set;
+import javax.xml.parsers.ParserConfigurationException;
+import org.apache.hop.core.exception.HopException;
+import org.apache.hop.core.row.IRowMeta;
+import org.apache.hop.core.util.Utils;
+import org.apache.hop.core.variables.IVariables;
+import org.apache.hop.core.xml.XmlHandler;
+import org.apache.hop.core.xml.XmlParserFactoryProducer;
+import org.apache.hop.i18n.BaseMessages;
+import org.apache.hop.pipeline.PipelineHopMeta;
+import org.apache.hop.pipeline.PipelineMeta;
+import org.apache.hop.pipeline.transform.TransformMeta;
+import org.apache.hop.pipeline.transforms.dummy.DummyMeta;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+/**
+ * What Load does, without the dialog: a copy of a pipeline with one transform 
and the transforms
+ * that send rows to it, and the XML document in a field of the first row that 
transform sends.
+ */
+final class UpstreamPipeline {
+  private static final Class<?> PKG = XmlJoinMeta.class;
+
+  private static final String DUMMY_PLUGIN_ID = "Dummy";
+
+  private UpstreamPipeline() {}
+
+  /**
+   * Copies the pipeline through its XML, the way it is copied elsewhere, and 
leaves out every
+   * transform that doesn't lead to the given one. A preview of the copy runs 
nothing after that
+   * transform: not the join, not an output.
+   *
+   * <p>A transform that one of the kept transforms sends rows to, over a hop 
or an error hop, stays
+   * as an empty Dummy. A Switch / case or a transform with error handling 
looks up the transforms
+   * it writes to by name, and fails when one of them is gone.
+   */
+  static PipelineMeta of(PipelineMeta pipelineMeta, IVariables variables, 
String transformName)

Review Comment:
   Load now names the transforms that may write and asks first: anything 
outside Input, Transform, Flow, Joins, Statistics, Validation and Inline, plus 
Pipeline/Workflow executor, Metadata injection, Execute tests, Dynamic SQL row, 
Mail input, the SQS reader, and unknown plugins. I did not swap in Dummies: 
Execute SQL, REST client and Mail are not in the Output category and would 
still have run.



##########
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 -> {

Review Comment:
   Fixed: after a click, changing the key field picks the node's key with that 
name and rewrites the statement. A statement typed by hand stays. Covered by 
`anotherKeyFieldChoosesTheKeyWithItsName`.



##########
plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/xmljoin/TargetDocumentPane.java:
##########
@@ -0,0 +1,775 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.xml.xmljoin;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.apache.hop.core.Const;
+import org.apache.hop.i18n.BaseMessages;
+import 
org.apache.hop.pipeline.transforms.xml.xmljoin.TargetXPathBuilder.KeyCandidate;
+import org.apache.hop.ui.core.PropsUi;
+import org.apache.hop.ui.core.gui.GuiResource;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * The first target document as a tree, beside the options of the XML join. 
Clicking a node writes
+ * the XPath statement that leads the transform to it; when elements go under 
the node of their key,
+ * the key of that node is chosen under the tree. The node the statement finds 
is highlighted, and
+ * {@link #check()} says what it finds, so a statement typed by hand can be 
checked against the
+ * document.
+ */
+final class TargetDocumentPane {
+  private static final Class<?> PKG = XmlJoinMeta.class;
+
+  /** Children listed under one node. The rest are counted: a document can be 
large. */
+  static final int MAX_CHILDREN = 200;
+
+  /** Nodes one Expand all shows at most: drawing the whole tree of a large 
document takes long. */
+  static final int MAX_EXPANDED = 5000;
+
+  private static final int MAX_VALUE_LENGTH = 40;
+
+  /** Whether and how the XPath statement finds a node in the document. */
+  enum Outcome {
+    /** No document is loaded. */
+    NO_DOCUMENT,
+    /** There is no statement to check, or it comes from the key field. */
+    NOT_CHECKED,
+    /**
+     * Under the node of their key: the statement uses ? other than in ='?', 
the check can't follow.
+     */
+    NOT_FOLLOWED,
+    /** The statement is not valid XPath. */
+    INVALID,
+    /** The statement finds no node. */
+    NOT_FOUND,
+    /**
+     * Under the node of their key: with the key of the node filled in, the 
statement finds another
+     * node first, the one the transform takes. {@link Check#node()} is that 
node.
+     */
+    KEY_NOT_UNIQUE,
+    /** Under the node of their key: with the key of the node filled in, it 
finds no node. */
+    KEY_FINDS_NO_NODE,
+    /** The statement finds a node, highlighted in the tree. */
+    FOUND,
+    /** The statement finds a node the tree does not list. */
+    FOUND_NOT_LISTED
+  }
+
+  /**
+   * What the XPath statement finds in the document.
+   *
+   * @param outcome whether and how it finds a node
+   * @param node the node it finds, as the tree shows it
+   * @param parent the parent of that node as the tree shows it, null for the 
root
+   * @param keyValue under the node of their key: the key of that node, null 
when the statement uses
+   *     none of its keys
+   * @param keyNodes under the node of their key: the nodes with a key the 
statement finds
+   * @param error why the statement is not valid
+   */
+  record Check(
+      Outcome outcome, String node, String parent, String keyValue, int 
keyNodes, String error) {
+    static Check of(Outcome outcome) {
+      return new Check(outcome, null, null, null, 0, null);
+    }
+  }
+
+  private final Group group;
+  private final ToolItem wExpandAll;
+  private final ToolItem wCollapseAll;
+  private final Label wStatus;
+  private final Tree wTree;
+  private final Label wlKey;
+  private final CCombo wKey;
+
+  private Document document;
+  private String transformName;
+  private boolean byKey;
+  private Supplier<List<String>> keyNames = List::of;
+  private BiConsumer<String, KeyCandidate> pickListener = (xpath, key) -> {};
+
+  /** The node clicked, or found by the statement. */
+  private Element picked;
+
+  /** What the statement finds, see {@link #check()}. */
+  private Check check = Check.of(Outcome.NO_DOCUMENT);
+
+  /** Set by {@link #find()}: why the statement is not valid XPath. */
+  private String findError;
+
+  /** Set by {@link #find()}: the elements the statement finds, for any key. */
+  private int foundCount;
+
+  /** Set by {@link #find()}: the statement uses ? in a way the check can't 
follow. */
+  private boolean notFollowed;
+
+  /** A mouse button or key went down in the tree: the next selection is 
someone's click. */
+  private boolean userInput;
+
+  private List<KeyCandidate> candidates = List.of();
+
+  /** The statement in the transform, variables resolved. */
+  private String xpath = "";
+
+  /**
+   * @param load loads the document, see {@link #setDocument}
+   */
+  TargetDocumentPane(Composite parent, Runnable load) {
+    group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+    PropsUi.setLook(group);
+    group.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Group.Label"));
+    FormLayout layout = new FormLayout();
+    layout.marginWidth = PropsUi.getFormMargin();
+    layout.marginHeight = PropsUi.getFormMargin();
+    group.setLayout(layout);
+    int margin = PropsUi.getMargin();
+    double zoom = PropsUi.getInstance().getZoomFactor();
+
+    Composite header = new Composite(group, SWT.NONE);
+    PropsUi.setLook(header);
+    GridLayout headerLayout = new GridLayout(3, false);
+    headerLayout.marginWidth = 0;
+    headerLayout.marginHeight = 0;
+    headerLayout.horizontalSpacing = margin;
+    header.setLayout(headerLayout);
+    FormData fdHeader = new FormData();
+    fdHeader.left = new FormAttachment(0, 0);
+    fdHeader.right = new FormAttachment(100, 0);
+    fdHeader.top = new FormAttachment(0, 0);
+    header.setLayoutData(fdHeader);
+
+    Button wLoad = new Button(header, SWT.PUSH);
+    PropsUi.setLook(wLoad);
+    wLoad.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Load.Button"));
+    wLoad.setToolTipText(BaseMessages.getString(PKG, 
"XmlJoin.Document.Load.Tooltip"));
+    wLoad.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+    wLoad.addListener(SWT.Selection, e -> load.run());
+
+    ToolBar wTools = new ToolBar(header, SWT.HORIZONTAL | SWT.FLAT);
+    PropsUi.setLook(wTools);
+    wTools.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+    wExpandAll = new ToolItem(wTools, SWT.PUSH);
+    wExpandAll.setImage(GuiResource.getInstance().getImageExpandAll());
+    wExpandAll.setToolTipText(
+        BaseMessages.getString(PKG, "XmlJoin.Document.ExpandAll.Tooltip", 
MAX_EXPANDED));
+    wExpandAll.addListener(SWT.Selection, e -> expandAll());
+    wCollapseAll = new ToolItem(wTools, SWT.PUSH);
+    wCollapseAll.setImage(GuiResource.getInstance().getImageCollapseAll());
+    wCollapseAll.setToolTipText(
+        BaseMessages.getString(PKG, "XmlJoin.Document.CollapseAll.Tooltip"));
+    wCollapseAll.addListener(SWT.Selection, e -> collapseAll());
+
+    wStatus = new Label(header, SWT.WRAP | SWT.LEFT);
+    PropsUi.setLook(wStatus);
+    GridData gdStatus = new GridData(SWT.FILL, SWT.CENTER, true, false);
+    gdStatus.widthHint = (int) (250 * zoom);
+    wStatus.setLayoutData(gdStatus);
+
+    wKey = new CCombo(group, SWT.BORDER | SWT.READ_ONLY);
+    PropsUi.setLook(wKey);
+    wKey.setToolTipText(BaseMessages.getString(PKG, 
"XmlJoin.Document.Key.Tooltip"));
+    wKey.addListener(SWT.Selection, e -> notifyPick());
+    wlKey = new Label(group, SWT.LEFT);
+    PropsUi.setLook(wlKey);
+    wlKey.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Key.Label"));
+    FormData fdlKey = new FormData();
+    fdlKey.left = new FormAttachment(0, 0);
+    fdlKey.top = new FormAttachment(wKey, 0, SWT.CENTER);
+    wlKey.setLayoutData(fdlKey);
+    FormData fdKey = new FormData();
+    fdKey.left = new FormAttachment(wlKey, margin);
+    fdKey.right = new FormAttachment(100, 0);
+    fdKey.bottom = new FormAttachment(100, 0);
+    wKey.setLayoutData(fdKey);
+
+    wTree = new Tree(group, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | 
SWT.H_SCROLL);
+    PropsUi.setLook(wTree);
+    FormData fdTree = new FormData();
+    fdTree.left = new FormAttachment(0, 0);
+    fdTree.right = new FormAttachment(100, 0);
+    fdTree.top = new FormAttachment(header, margin);
+    fdTree.bottom = new FormAttachment(wKey, -margin);
+    fdTree.width = (int) (350 * zoom);
+    fdTree.height = (int) (250 * zoom);
+    wTree.setLayoutData(fdTree);
+    wTree.addListener(SWT.Expand, e -> fill((TreeItem) e.item));
+    wTree.addListener(SWT.MouseDown, e -> userInput = true);
+    wTree.addListener(SWT.KeyDown, e -> userInput = true);
+    wTree.addListener(SWT.Selection, e -> clicked());
+
+    setByKey(false);
+    enableTools();
+  }
+
+  void setPickListener(BiConsumer<String, KeyCandidate> pickListener) {
+    this.pickListener = pickListener;
+  }
+
+  /** The names to choose a key by, in order: the key field, or else the 
source fields. */
+  void setKeyNames(Supplier<List<String>> keyNames) {
+    this.keyNames = keyNames;
+  }
+
+  /** Shows a document, opened at the node the statement finds. */
+  void setDocument(Document document, String transformName) {
+    this.document = document;
+    this.transformName = transformName;
+    wTree.removeAll();
+    picked = null;
+    if (document != null) {
+      TreeItem root = addItem(null, document.getDocumentElement());
+      fill(root);
+      root.setExpanded(true);
+    }
+    enableTools();
+    show(xpath);
+  }
+
+  /** Under one node, or under the node of each key: the key row is only used 
for the latter. */
+  void setByKey(boolean byKey) {
+    this.byKey = byKey;
+    wlKey.setEnabled(byKey);
+    wKey.setEnabled(byKey);
+    chooseKey(null);
+    updateStatus();
+  }
+
+  /** Highlights the node the statement finds, and works out what it finds, 
see {@link #check()}. */
+  void show(String statement) {
+    xpath = Const.NVL(statement, "").trim();
+    if (document == null) {
+      check = Check.of(Outcome.NO_DOCUMENT);
+    } else {
+      Element found = find();
+      TreeItem item = found == null ? null : itemOf(found);
+      if (item == null) {
+        wTree.deselectAll();
+        picked = null;
+      } else {
+        wTree.setSelection(item);
+        wTree.showItem(item);
+        picked = found;
+      }
+      KeyCandidate key = keyInStatement(found);
+      chooseKey(key);
+      check = checkOf(found, item != null, key);
+    }
+    updateStatus();
+  }
+
+  /** What the statement finds in the document, as of the last {@link #show}. 
*/
+  Check check() {
+    return check;
+  }
+
+  private Check checkOf(Element found, boolean listed, KeyCandidate key) {
+    if (xpath.isEmpty() || byKey && 
TargetXPathBuilder.KEY_PLACEHOLDER.equals(xpath)) {
+      return Check.of(Outcome.NOT_CHECKED);
+    }
+    if (findError != null) {
+      return new Check(Outcome.INVALID, null, null, null, 0, findError);
+    }
+    if (notFollowed) {
+      return Check.of(Outcome.NOT_FOLLOWED);
+    }
+    if (found == null) {
+      return Check.of(Outcome.NOT_FOUND);
+    }
+    if (byKey && key != null) {
+      // What the transform does with the key of this node: it takes the first 
node it finds
+      Node taken = nodeOf(TargetXPathBuilder.forKeyValue(xpath, key.value()));
+      if (!(taken instanceof Element takenElement)) {
+        return new Check(
+            Outcome.KEY_FINDS_NO_NODE,
+            describe(found),
+            parentOf(found),
+            key.value(),
+            foundCount,
+            null);
+      }
+      if (takenElement != found) {
+        return new Check(
+            Outcome.KEY_NOT_UNIQUE,
+            describe(takenElement),
+            parentOf(takenElement),
+            key.value(),
+            foundCount,
+            null);
+      }
+    }
+    return new Check(
+        listed ? Outcome.FOUND : Outcome.FOUND_NOT_LISTED,
+        describe(found),
+        parentOf(found),
+        byKey && key != null ? key.value() : null,
+        byKey ? foundCount : 1,
+        null);
+  }
+
+  private static String parentOf(Element element) {
+    return element.getParentNode() instanceof Element parent ? 
describe(parent) : null;
+  }
+
+  /** The node a statement finds the way the transform evaluates it: the first 
one. */
+  private Node nodeOf(String statement) {
+    try {
+      return (Node)
+          XPathFactory.newInstance().newXPath().evaluate(statement, document, 
XPathConstants.NODE);
+    } catch (XPathExpressionException e) {
+      return null;
+    }
+  }
+
+  /** Writes the statement for the node again, after the join mode changed. */
+  void pickAgain() {
+    notifyPick();
+  }
+
+  /**
+   * Opens every node under the selected node, or under the root when no node 
is selected. It opens
+   * level by level and stops once {@link #MAX_EXPANDED} nodes show, so a 
large document opens its
+   * upper levels.
+   */
+  private void expandAll() {
+    TreeItem start = selectedOrRoot();
+    if (start == null) {
+      return;
+    }
+    wTree.setRedraw(false);
+    try {
+      Deque<TreeItem> next = new ArrayDeque<>(List.of(start));
+      int shown = 0;
+      while (!next.isEmpty() && shown < MAX_EXPANDED) {
+        TreeItem item = next.poll();
+        fill(item);
+        if (item.getItemCount() == 0) {
+          continue;
+        }
+        item.setExpanded(true);
+        for (TreeItem child : item.getItems()) {
+          shown++;
+          if (child.getData() instanceof Element) {
+            next.add(child);
+          }
+        }
+      }
+    } finally {
+      wTree.setRedraw(true);
+    }
+  }
+
+  /** Closes the selected node and every node under it, or the whole document. 
*/
+  private void collapseAll() {
+    TreeItem start = selectedOrRoot();
+    if (start == null) {
+      return;
+    }
+    List<TreeItem> open = new ArrayList<>();
+    Deque<TreeItem> next = new ArrayDeque<>(List.of(start));
+    while (!next.isEmpty()) {
+      TreeItem item = next.pop();
+      if (item.getItemCount() > 0) {
+        open.add(item);
+        for (TreeItem child : item.getItems()) {
+          next.push(child);
+        }
+      }
+    }
+    wTree.setRedraw(false);
+    try {
+      // The deepest nodes first, so every node is closed when its parent 
closes
+      for (int i = open.size() - 1; i >= 0; i--) {
+        open.get(i).setExpanded(false);
+      }
+    } finally {
+      wTree.setRedraw(true);
+    }
+  }
+
+  /** The selected node, or the root when no node is selected. */
+  private TreeItem selectedOrRoot() {
+    TreeItem[] selection = wTree.getSelection();
+    if (selection.length == 1 && selection[0].getData() instanceof Element) {
+      return selection[0];
+    }
+    return wTree.getItemCount() == 0 ? null : wTree.getItem(0);
+  }
+
+  private void enableTools() {
+    wExpandAll.setEnabled(document != null);
+    wCollapseAll.setEnabled(document != null);
+  }
+
+  private void clicked() {
+    TreeItem[] selection = wTree.getSelection();
+    boolean byInput = userInput;
+    userInput = false;
+    if (!byInput
+        && picked == null
+        && selection.length == 1
+        && wTree.getItemCount() > 0
+        && selection[0] == wTree.getItem(0)) {
+      // Nobody clicked: GTK selects the first row when the tree gets the 
focus with nothing
+      // selected. That must not write over the statement.
+      wTree.deselectAll();
+      return;
+    }
+    picked =
+        selection.length == 1 && selection[0].getData() instanceof Element 
element ? element : null;
+    chooseKey(selectedKey());
+    notifyPick();
+    updateStatus();
+  }
+
+  private void notifyPick() {
+    if (picked == null) {
+      return;
+    }
+    KeyCandidate key = null;
+    String statement;
+    if (byKey) {
+      key = selectedKey();
+      if (key == null) {
+        updateStatus();
+        return;
+      }
+      statement = TargetXPathBuilder.xpath(picked, key);
+    } else {
+      statement = TargetXPathBuilder.xpath(picked);
+    }
+    xpath = statement;
+    pickListener.accept(statement, key);
+    updateStatus();
+  }
+
+  /**
+   * Fills the key row for the picked node. The key to select is the preferred 
one, or one with the
+   * same name as before, or one named like the key names, or the first.
+   */
+  private void chooseKey(KeyCandidate preferred) {
+    KeyCandidate previous = selectedKey();
+    candidates = byKey && picked != null ? 
TargetXPathBuilder.keyCandidates(picked) : List.of();
+    
wKey.setItems(candidates.stream().map(TargetDocumentPane::describe).toArray(String[]::new));
+    KeyCandidate choice = sameKey(preferred);
+    if (choice == null) {
+      choice = sameKey(previous);
+    }
+    if (choice == null && !candidates.isEmpty()) {
+      for (String name : keyNames.get()) {

Review Comment:
   The fields are now looked up once per transform per dialog and reused, for 
the key names as well as the field combos.



##########
plugins/transforms/xml/src/main/java/org/apache/hop/pipeline/transforms/xml/xmljoin/TargetDocumentPane.java:
##########
@@ -0,0 +1,775 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hop.pipeline.transforms.xml.xmljoin;
+
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Deque;
+import java.util.List;
+import java.util.function.BiConsumer;
+import java.util.function.Supplier;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathExpressionException;
+import javax.xml.xpath.XPathFactory;
+import org.apache.hop.core.Const;
+import org.apache.hop.i18n.BaseMessages;
+import 
org.apache.hop.pipeline.transforms.xml.xmljoin.TargetXPathBuilder.KeyCandidate;
+import org.apache.hop.ui.core.PropsUi;
+import org.apache.hop.ui.core.gui.GuiResource;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CCombo;
+import org.eclipse.swt.layout.FormAttachment;
+import org.eclipse.swt.layout.FormData;
+import org.eclipse.swt.layout.FormLayout;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.ToolBar;
+import org.eclipse.swt.widgets.ToolItem;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+import org.w3c.dom.NamedNodeMap;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+/**
+ * The first target document as a tree, beside the options of the XML join. 
Clicking a node writes
+ * the XPath statement that leads the transform to it; when elements go under 
the node of their key,
+ * the key of that node is chosen under the tree. The node the statement finds 
is highlighted, and
+ * {@link #check()} says what it finds, so a statement typed by hand can be 
checked against the
+ * document.
+ */
+final class TargetDocumentPane {
+  private static final Class<?> PKG = XmlJoinMeta.class;
+
+  /** Children listed under one node. The rest are counted: a document can be 
large. */
+  static final int MAX_CHILDREN = 200;
+
+  /** Nodes one Expand all shows at most: drawing the whole tree of a large 
document takes long. */
+  static final int MAX_EXPANDED = 5000;
+
+  private static final int MAX_VALUE_LENGTH = 40;
+
+  /** Whether and how the XPath statement finds a node in the document. */
+  enum Outcome {
+    /** No document is loaded. */
+    NO_DOCUMENT,
+    /** There is no statement to check, or it comes from the key field. */
+    NOT_CHECKED,
+    /**
+     * Under the node of their key: the statement uses ? other than in ='?', 
the check can't follow.
+     */
+    NOT_FOLLOWED,
+    /** The statement is not valid XPath. */
+    INVALID,
+    /** The statement finds no node. */
+    NOT_FOUND,
+    /**
+     * Under the node of their key: with the key of the node filled in, the 
statement finds another
+     * node first, the one the transform takes. {@link Check#node()} is that 
node.
+     */
+    KEY_NOT_UNIQUE,
+    /** Under the node of their key: with the key of the node filled in, it 
finds no node. */
+    KEY_FINDS_NO_NODE,
+    /** The statement finds a node, highlighted in the tree. */
+    FOUND,
+    /** The statement finds a node the tree does not list. */
+    FOUND_NOT_LISTED
+  }
+
+  /**
+   * What the XPath statement finds in the document.
+   *
+   * @param outcome whether and how it finds a node
+   * @param node the node it finds, as the tree shows it
+   * @param parent the parent of that node as the tree shows it, null for the 
root
+   * @param keyValue under the node of their key: the key of that node, null 
when the statement uses
+   *     none of its keys
+   * @param keyNodes under the node of their key: the nodes with a key the 
statement finds
+   * @param error why the statement is not valid
+   */
+  record Check(
+      Outcome outcome, String node, String parent, String keyValue, int 
keyNodes, String error) {
+    static Check of(Outcome outcome) {
+      return new Check(outcome, null, null, null, 0, null);
+    }
+  }
+
+  private final Group group;
+  private final ToolItem wExpandAll;
+  private final ToolItem wCollapseAll;
+  private final Label wStatus;
+  private final Tree wTree;
+  private final Label wlKey;
+  private final CCombo wKey;
+
+  private Document document;
+  private String transformName;
+  private boolean byKey;
+  private Supplier<List<String>> keyNames = List::of;
+  private BiConsumer<String, KeyCandidate> pickListener = (xpath, key) -> {};
+
+  /** The node clicked, or found by the statement. */
+  private Element picked;
+
+  /** What the statement finds, see {@link #check()}. */
+  private Check check = Check.of(Outcome.NO_DOCUMENT);
+
+  /** Set by {@link #find()}: why the statement is not valid XPath. */
+  private String findError;
+
+  /** Set by {@link #find()}: the elements the statement finds, for any key. */
+  private int foundCount;
+
+  /** Set by {@link #find()}: the statement uses ? in a way the check can't 
follow. */
+  private boolean notFollowed;
+
+  /** A mouse button or key went down in the tree: the next selection is 
someone's click. */
+  private boolean userInput;
+
+  private List<KeyCandidate> candidates = List.of();
+
+  /** The statement in the transform, variables resolved. */
+  private String xpath = "";
+
+  /**
+   * @param load loads the document, see {@link #setDocument}
+   */
+  TargetDocumentPane(Composite parent, Runnable load) {
+    group = new Group(parent, SWT.SHADOW_ETCHED_IN);
+    PropsUi.setLook(group);
+    group.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Group.Label"));
+    FormLayout layout = new FormLayout();
+    layout.marginWidth = PropsUi.getFormMargin();
+    layout.marginHeight = PropsUi.getFormMargin();
+    group.setLayout(layout);
+    int margin = PropsUi.getMargin();
+    double zoom = PropsUi.getInstance().getZoomFactor();
+
+    Composite header = new Composite(group, SWT.NONE);
+    PropsUi.setLook(header);
+    GridLayout headerLayout = new GridLayout(3, false);
+    headerLayout.marginWidth = 0;
+    headerLayout.marginHeight = 0;
+    headerLayout.horizontalSpacing = margin;
+    header.setLayout(headerLayout);
+    FormData fdHeader = new FormData();
+    fdHeader.left = new FormAttachment(0, 0);
+    fdHeader.right = new FormAttachment(100, 0);
+    fdHeader.top = new FormAttachment(0, 0);
+    header.setLayoutData(fdHeader);
+
+    Button wLoad = new Button(header, SWT.PUSH);
+    PropsUi.setLook(wLoad);
+    wLoad.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Load.Button"));
+    wLoad.setToolTipText(BaseMessages.getString(PKG, 
"XmlJoin.Document.Load.Tooltip"));
+    wLoad.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+    wLoad.addListener(SWT.Selection, e -> load.run());
+
+    ToolBar wTools = new ToolBar(header, SWT.HORIZONTAL | SWT.FLAT);
+    PropsUi.setLook(wTools);
+    wTools.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
+    wExpandAll = new ToolItem(wTools, SWT.PUSH);
+    wExpandAll.setImage(GuiResource.getInstance().getImageExpandAll());
+    wExpandAll.setToolTipText(
+        BaseMessages.getString(PKG, "XmlJoin.Document.ExpandAll.Tooltip", 
MAX_EXPANDED));
+    wExpandAll.addListener(SWT.Selection, e -> expandAll());
+    wCollapseAll = new ToolItem(wTools, SWT.PUSH);
+    wCollapseAll.setImage(GuiResource.getInstance().getImageCollapseAll());
+    wCollapseAll.setToolTipText(
+        BaseMessages.getString(PKG, "XmlJoin.Document.CollapseAll.Tooltip"));
+    wCollapseAll.addListener(SWT.Selection, e -> collapseAll());
+
+    wStatus = new Label(header, SWT.WRAP | SWT.LEFT);
+    PropsUi.setLook(wStatus);
+    GridData gdStatus = new GridData(SWT.FILL, SWT.CENTER, true, false);
+    gdStatus.widthHint = (int) (250 * zoom);
+    wStatus.setLayoutData(gdStatus);
+
+    wKey = new CCombo(group, SWT.BORDER | SWT.READ_ONLY);
+    PropsUi.setLook(wKey);
+    wKey.setToolTipText(BaseMessages.getString(PKG, 
"XmlJoin.Document.Key.Tooltip"));
+    wKey.addListener(SWT.Selection, e -> notifyPick());
+    wlKey = new Label(group, SWT.LEFT);
+    PropsUi.setLook(wlKey);
+    wlKey.setText(BaseMessages.getString(PKG, "XmlJoin.Document.Key.Label"));
+    FormData fdlKey = new FormData();
+    fdlKey.left = new FormAttachment(0, 0);
+    fdlKey.top = new FormAttachment(wKey, 0, SWT.CENTER);
+    wlKey.setLayoutData(fdlKey);
+    FormData fdKey = new FormData();
+    fdKey.left = new FormAttachment(wlKey, margin);
+    fdKey.right = new FormAttachment(100, 0);
+    fdKey.bottom = new FormAttachment(100, 0);
+    wKey.setLayoutData(fdKey);
+
+    wTree = new Tree(group, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | 
SWT.H_SCROLL);
+    PropsUi.setLook(wTree);
+    FormData fdTree = new FormData();
+    fdTree.left = new FormAttachment(0, 0);
+    fdTree.right = new FormAttachment(100, 0);
+    fdTree.top = new FormAttachment(header, margin);
+    fdTree.bottom = new FormAttachment(wKey, -margin);
+    fdTree.width = (int) (350 * zoom);
+    fdTree.height = (int) (250 * zoom);
+    wTree.setLayoutData(fdTree);
+    wTree.addListener(SWT.Expand, e -> fill((TreeItem) e.item));
+    wTree.addListener(SWT.MouseDown, e -> userInput = true);
+    wTree.addListener(SWT.KeyDown, e -> userInput = true);
+    wTree.addListener(SWT.Selection, e -> clicked());
+
+    setByKey(false);
+    enableTools();
+  }
+
+  void setPickListener(BiConsumer<String, KeyCandidate> pickListener) {
+    this.pickListener = pickListener;
+  }
+
+  /** The names to choose a key by, in order: the key field, or else the 
source fields. */
+  void setKeyNames(Supplier<List<String>> keyNames) {
+    this.keyNames = keyNames;
+  }
+
+  /** Shows a document, opened at the node the statement finds. */
+  void setDocument(Document document, String transformName) {
+    this.document = document;
+    this.transformName = transformName;
+    wTree.removeAll();
+    picked = null;
+    if (document != null) {
+      TreeItem root = addItem(null, document.getDocumentElement());
+      fill(root);
+      root.setExpanded(true);
+    }
+    enableTools();
+    show(xpath);
+  }
+
+  /** Under one node, or under the node of each key: the key row is only used 
for the latter. */
+  void setByKey(boolean byKey) {
+    this.byKey = byKey;
+    wlKey.setEnabled(byKey);
+    wKey.setEnabled(byKey);
+    chooseKey(null);
+    updateStatus();
+  }
+
+  /** Highlights the node the statement finds, and works out what it finds, 
see {@link #check()}. */
+  void show(String statement) {
+    xpath = Const.NVL(statement, "").trim();
+    if (document == null) {
+      check = Check.of(Outcome.NO_DOCUMENT);
+    } else {
+      Element found = find();
+      TreeItem item = found == null ? null : itemOf(found);
+      if (item == null) {
+        wTree.deselectAll();
+        picked = null;
+      } else {
+        wTree.setSelection(item);
+        wTree.showItem(item);
+        picked = found;
+      }
+      KeyCandidate key = keyInStatement(found);
+      chooseKey(key);
+      check = checkOf(found, item != null, key);
+    }
+    updateStatus();
+  }
+
+  /** What the statement finds in the document, as of the last {@link #show}. 
*/
+  Check check() {
+    return check;
+  }
+
+  private Check checkOf(Element found, boolean listed, KeyCandidate key) {
+    if (xpath.isEmpty() || byKey && 
TargetXPathBuilder.KEY_PLACEHOLDER.equals(xpath)) {
+      return Check.of(Outcome.NOT_CHECKED);
+    }
+    if (findError != null) {
+      return new Check(Outcome.INVALID, null, null, null, 0, findError);
+    }
+    if (notFollowed) {
+      return Check.of(Outcome.NOT_FOLLOWED);
+    }
+    if (found == null) {
+      return Check.of(Outcome.NOT_FOUND);
+    }
+    if (byKey && key != null) {
+      // What the transform does with the key of this node: it takes the first 
node it finds
+      Node taken = nodeOf(TargetXPathBuilder.forKeyValue(xpath, key.value()));
+      if (!(taken instanceof Element takenElement)) {
+        return new Check(
+            Outcome.KEY_FINDS_NO_NODE,
+            describe(found),
+            parentOf(found),
+            key.value(),
+            foundCount,
+            null);
+      }
+      if (takenElement != found) {
+        return new Check(
+            Outcome.KEY_NOT_UNIQUE,
+            describe(takenElement),
+            parentOf(takenElement),
+            key.value(),
+            foundCount,
+            null);
+      }
+    }
+    return new Check(
+        listed ? Outcome.FOUND : Outcome.FOUND_NOT_LISTED,
+        describe(found),
+        parentOf(found),
+        byKey && key != null ? key.value() : null,
+        byKey ? foundCount : 1,
+        null);
+  }
+
+  private static String parentOf(Element element) {
+    return element.getParentNode() instanceof Element parent ? 
describe(parent) : null;
+  }
+
+  /** The node a statement finds the way the transform evaluates it: the first 
one. */
+  private Node nodeOf(String statement) {
+    try {
+      return (Node)
+          XPathFactory.newInstance().newXPath().evaluate(statement, document, 
XPathConstants.NODE);
+    } catch (XPathExpressionException e) {
+      return null;
+    }
+  }
+
+  /** Writes the statement for the node again, after the join mode changed. */
+  void pickAgain() {
+    notifyPick();
+  }
+
+  /**
+   * Opens every node under the selected node, or under the root when no node 
is selected. It opens
+   * level by level and stops once {@link #MAX_EXPANDED} nodes show, so a 
large document opens its
+   * upper levels.
+   */
+  private void expandAll() {
+    TreeItem start = selectedOrRoot();
+    if (start == null) {
+      return;
+    }
+    wTree.setRedraw(false);
+    try {
+      Deque<TreeItem> next = new ArrayDeque<>(List.of(start));
+      int shown = 0;
+      while (!next.isEmpty() && shown < MAX_EXPANDED) {
+        TreeItem item = next.poll();
+        fill(item);
+        if (item.getItemCount() == 0) {
+          continue;
+        }
+        item.setExpanded(true);
+        for (TreeItem child : item.getItems()) {
+          shown++;
+          if (child.getData() instanceof Element) {
+            next.add(child);
+          }
+        }
+      }
+    } finally {
+      wTree.setRedraw(true);
+    }
+  }
+
+  /** Closes the selected node and every node under it, or the whole document. 
*/
+  private void collapseAll() {
+    TreeItem start = selectedOrRoot();
+    if (start == null) {
+      return;
+    }
+    List<TreeItem> open = new ArrayList<>();
+    Deque<TreeItem> next = new ArrayDeque<>(List.of(start));
+    while (!next.isEmpty()) {
+      TreeItem item = next.pop();
+      if (item.getItemCount() > 0) {
+        open.add(item);
+        for (TreeItem child : item.getItems()) {
+          next.push(child);
+        }
+      }
+    }
+    wTree.setRedraw(false);
+    try {
+      // The deepest nodes first, so every node is closed when its parent 
closes
+      for (int i = open.size() - 1; i >= 0; i--) {
+        open.get(i).setExpanded(false);
+      }
+    } finally {
+      wTree.setRedraw(true);
+    }
+  }
+
+  /** The selected node, or the root when no node is selected. */
+  private TreeItem selectedOrRoot() {
+    TreeItem[] selection = wTree.getSelection();
+    if (selection.length == 1 && selection[0].getData() instanceof Element) {
+      return selection[0];
+    }
+    return wTree.getItemCount() == 0 ? null : wTree.getItem(0);
+  }
+
+  private void enableTools() {
+    wExpandAll.setEnabled(document != null);
+    wCollapseAll.setEnabled(document != null);
+  }
+
+  private void clicked() {
+    TreeItem[] selection = wTree.getSelection();
+    boolean byInput = userInput;
+    userInput = false;
+    if (!byInput
+        && picked == null
+        && selection.length == 1
+        && wTree.getItemCount() > 0
+        && selection[0] == wTree.getItem(0)) {
+      // Nobody clicked: GTK selects the first row when the tree gets the 
focus with nothing
+      // selected. That must not write over the statement.
+      wTree.deselectAll();
+      return;
+    }
+    picked =
+        selection.length == 1 && selection[0].getData() instanceof Element 
element ? element : null;
+    chooseKey(selectedKey());
+    notifyPick();
+    updateStatus();
+  }
+
+  private void notifyPick() {
+    if (picked == null) {
+      return;
+    }
+    KeyCandidate key = null;
+    String statement;
+    if (byKey) {
+      key = selectedKey();
+      if (key == null) {
+        updateStatus();
+        return;
+      }
+      statement = TargetXPathBuilder.xpath(picked, key);
+    } else {
+      statement = TargetXPathBuilder.xpath(picked);
+    }
+    xpath = statement;
+    pickListener.accept(statement, key);
+    updateStatus();
+  }
+
+  /**
+   * Fills the key row for the picked node. The key to select is the preferred 
one, or one with the
+   * same name as before, or one named like the key names, or the first.
+   */
+  private void chooseKey(KeyCandidate preferred) {
+    KeyCandidate previous = selectedKey();
+    candidates = byKey && picked != null ? 
TargetXPathBuilder.keyCandidates(picked) : List.of();
+    
wKey.setItems(candidates.stream().map(TargetDocumentPane::describe).toArray(String[]::new));
+    KeyCandidate choice = sameKey(preferred);
+    if (choice == null) {
+      choice = sameKey(previous);
+    }
+    if (choice == null && !candidates.isEmpty()) {
+      for (String name : keyNames.get()) {
+        choice = TargetXPathBuilder.findByName(candidates, name);
+        if (choice != null) {
+          break;
+        }
+      }
+    }
+    if (choice == null && !candidates.isEmpty()) {
+      // A key that tells this node apart, so the transform finds it with its 
value
+      choice =
+          
candidates.stream().filter(this::leadsToPicked).findFirst().orElse(candidates.get(0));
+    }
+    if (choice != null) {
+      wKey.select(candidates.indexOf(choice));
+    }
+  }
+
+  /** Whether the statement for the picked node with this key, its value 
filled in, finds it. */
+  private boolean leadsToPicked(KeyCandidate key) {
+    String statement = TargetXPathBuilder.xpath(picked, key);
+    return nodeOf(TargetXPathBuilder.forKeyValue(statement, key.value())) == 
picked;
+  }
+
+  private KeyCandidate selectedKey() {
+    int index = wKey.getSelectionIndex();
+    return index >= 0 && index < candidates.size() ? candidates.get(index) : 
null;
+  }
+
+  /** The candidate with the same name on a node with the same name. */
+  private KeyCandidate sameKey(KeyCandidate key) {
+    if (key == null) {
+      return null;
+    }
+    for (KeyCandidate candidate : candidates) {
+      if (candidate.name().equals(key.name())
+          && 
candidate.holder().getNodeName().equals(key.holder().getNodeName())) {
+        return candidate;
+      }
+    }
+    return null;
+  }
+
+  /**
+   * The key of a node the statement uses, if any: the key a click wrote the 
statement for, or else
+   * the key whose predicate follows the name of its node, as in 
/order[@id='?']. The predicate
+   * alone is not enough: a node and its parent can have a key of the same 
name.
+   */
+  private KeyCandidate keyInStatement(Element node) {
+    if (!byKey || node == null) {
+      return null;
+    }
+    List<KeyCandidate> keys = TargetXPathBuilder.keyCandidates(node);
+    for (KeyCandidate candidate : keys) {
+      if (TargetXPathBuilder.xpath(node, candidate).equals(xpath)) {
+        return candidate;
+      }
+    }
+    for (KeyCandidate candidate : keys) {
+      if (xpath.contains(candidate.stepWithPredicate())) {
+        return candidate;
+      }
+    }
+    for (KeyCandidate candidate : keys) {
+      if (xpath.contains(candidate.predicate())) {
+        return candidate;
+      }
+    }
+    return null;
+  }
+
+  /**
+   * The node the statement finds. Under one node that is the first node in 
the document, as the
+   * transform takes it. Under the node of their key, '?' stands for any key, 
so the picked node
+   * stays highlighted when the statement finds it among the others.
+   */
+  private Element find() {
+    findError = null;
+    foundCount = 0;
+    notFollowed = false;
+    if (xpath.isEmpty() || byKey && 
TargetXPathBuilder.KEY_PLACEHOLDER.equals(xpath)) {
+      return null;
+    }
+    String statement = xpath;
+    if (byKey) {
+      // Valid XPath once the transform fills in a key?
+      try {
+        XPathFactory.newInstance()

Review Comment:
   One `XPath` on the pane now.



##########
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();

Review Comment:
   It already relaid out only on a height change; now only when the line has to 
grow.



##########
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());

Review Comment:
   Back to on-focus, with a busy cursor.



-- 
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