From a0885a45812d5ece156e56972adbda07d27e93b1 Mon Sep 17 00:00:00 2001 From: Gionata Boccalini Date: Sun, 28 Jan 2024 18:53:20 +0100 Subject: [PATCH 1/6] Add method to configure the warning signal in case of fail in item resolution. --- .../widgets/treemapper/ISemanticTreeMapperSupport.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/ISemanticTreeMapperSupport.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/ISemanticTreeMapperSupport.java index f8804c6a3..c434a6424 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/ISemanticTreeMapperSupport.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/ISemanticTreeMapperSupport.java @@ -50,4 +50,10 @@ public interface ISemanticTreeMapperSupport { * @return its left bound */ public R resolveRightItem(M semanticMappingObject); + + /** + * Whether or not to signal a warning in case of fail in item resolution. + * @return true to signal + */ + public boolean signalOnMissingItem(); } From 2aa5b45f35454413834938580fbe35d7e53f582e Mon Sep 17 00:00:00 2001 From: Gionata Boccalini Date: Sun, 28 Jan 2024 18:55:10 +0100 Subject: [PATCH 2/6] Add control weights and dnd enable flag for tree configuration provider --- .../TreeMapperUIConfigProvider.java | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java index 5e5ddf2da..1fcd601db 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java @@ -29,11 +29,17 @@ public final class TreeMapperUIConfigProvider { private int defaultWidth; private Color defaultColor; - public TreeMapperUIConfigProvider(Color defaultColor, int defaultWidth, Color selectedColor, int selectedWidth) { + private int[] controlWeights; + + private boolean dndEnabled; + + public TreeMapperUIConfigProvider(Color defaultColor, int defaultWidth, Color selectedColor, int selectedWidth, + int[] controlWeights) { this.selectedColor = selectedColor; this.selectedWidth = selectedWidth; this.defaultColor = defaultColor; this.defaultWidth = defaultWidth; + this.controlWeights = controlWeights; } /** @@ -64,4 +70,24 @@ public int getHoverArrowWidth() { return selectedWidth; } + /** + * @return the main control weights + */ + public int[] getControlWeights() { + return controlWeights; + } + + /** + * @return the dndEnabled + */ + public boolean isDndEnabled() { + return dndEnabled; + } + + /** + * @param dndEnabled the dndEnabled to set + */ + public void setDndEnabled(boolean dndEnabled) { + this.dndEnabled = dndEnabled; + } } From 3661ee3f000e8335e9c857011173d3c2a4141b8c Mon Sep 17 00:00:00 2001 From: Gionata Boccalini Date: Sun, 28 Jan 2024 19:00:12 +0100 Subject: [PATCH 3/6] Add configuration element use in TreeMapper.java Use of control weight for the main sash form, dnd enable on flag, missing item signal enabled on flag. --- .../nebula/widgets/treemapper/TreeMapper.java | 28 ++++++++++++------- .../TreeMapperUIConfigProvider.java | 6 +++- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java index bed211b63..e54f8b5eb 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java @@ -164,10 +164,12 @@ public void treeCollapsed(TreeEvent e) { leftTreeViewer.getTree().addTreeListener(treeListener); rightTreeViewer.getTree().addTreeListener(treeListener); - control.setWeights(new int[] { 1, 2, 1} ); + control.setWeights(this.uiConfig.getControlWeights()); - bindTreeForDND(leftTreeViewer, rightTreeViewer, SWT.LEFT_TO_RIGHT); - bindTreeForDND(rightTreeViewer, leftTreeViewer, SWT.RIGHT_TO_LEFT); + if (this.uiConfig.isDndEnabled()) { + bindTreeForDND(leftTreeViewer, rightTreeViewer, SWT.LEFT_TO_RIGHT); + bindTreeForDND(rightTreeViewer, leftTreeViewer, SWT.RIGHT_TO_LEFT); + } } /** @@ -344,11 +346,14 @@ private boolean drawMapping(final M mapping) { boolean leftItemVisible = true; TreeItem leftTreeItem = (TreeItem) leftTreeViewer.testFindItem(semanticSupport.resolveLeftItem(mapping)); if (leftTreeItem == null) { - Policy.getLog().log( + if (semanticSupport.signalOnMissingItem()) { + Policy.getLog().log( new Status(IStatus.ERROR, "org.eclipse.nebula.widgets.treemapper", "Could not find left entry of mapping " + mapping.toString() + " in left treeViewer.")); - return false; + return false; + } + return true; } TreeItem lastVisibleLeftTreeItem = leftTreeItem; while (leftTreeItem.getParentItem() != null) { @@ -366,11 +371,14 @@ private boolean drawMapping(final M mapping) { boolean rightItemVisible = true; TreeItem rightTreeItem = (TreeItem) rightTreeViewer.testFindItem(semanticSupport.resolveRightItem(mapping)); if (rightTreeItem == null) { - Policy.getLog().log( - new Status(IStatus.ERROR, - "org.eclipse.nebula.widgets.treemapper", - "Could not find right entry of mapping " + mapping.toString() + " in right treeViewer.")); - return false; + if (semanticSupport.signalOnMissingItem()) { + Policy.getLog().log( + new Status(IStatus.ERROR, + "org.eclipse.nebula.widgets.treemapper", + "Could not find right entry of mapping " + mapping.toString() + " in right treeViewer.")); + return false; + } + return true; } TreeItem lastVisibleRightTreeItem = rightTreeItem; while (rightTreeItem.getParentItem() != null) { diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java index 1fcd601db..ecdddcdaa 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapperUIConfigProvider.java @@ -41,7 +41,11 @@ public TreeMapperUIConfigProvider(Color defaultColor, int defaultWidth, Color se this.defaultWidth = defaultWidth; this.controlWeights = controlWeights; } - + + public TreeMapperUIConfigProvider(Color defaultColor, int defaultWidth, Color selectedColor, int selectedWidth) { + this(defaultColor, defaultWidth, selectedColor, selectedWidth, new int[] { 1, 2, 1}); + } + /** * @return */ From 8db039ba6114a3b6925a1789d84b14444f47ea0c Mon Sep 17 00:00:00 2001 From: Gionata Boccalini Date: Sun, 28 Jan 2024 19:16:52 +0100 Subject: [PATCH 4/6] Add account for tree header height Add int offset for both left and right tree mapping drawing, to account for tree header if present. --- .../nebula/widgets/treemapper/TreeMapper.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java index e54f8b5eb..627981b1b 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java @@ -342,7 +342,12 @@ private boolean drawMapping(final M mapping) { final LinkFigure arrowFigure = new LinkFigure(linkRootFigure); - { + { + int leftHeaderOffset = 0; + if (leftTreeViewer.getTree().getHeaderVisible()) { + leftHeaderOffset = leftTreeViewer.getTree().getHeaderHeight(); + } + boolean leftItemVisible = true; TreeItem leftTreeItem = (TreeItem) leftTreeViewer.testFindItem(semanticSupport.resolveLeftItem(mapping)); if (leftTreeItem == null) { @@ -363,11 +368,16 @@ private boolean drawMapping(final M mapping) { } leftTreeItem = leftTreeItem.getParentItem(); } - arrowFigure.setLeftPoint(0, lastVisibleLeftTreeItem.getBounds().y + lastVisibleLeftTreeItem.getBounds().height / 2); + arrowFigure.setLeftPoint(0, leftHeaderOffset + lastVisibleLeftTreeItem.getBounds().y + lastVisibleLeftTreeItem.getBounds().height / 2); arrowFigure.setLeftMappingVisible(leftItemVisible); } { + int rightHeaderOffset = 0; + if (rightTreeViewer.getTree().getHeaderVisible()) { + rightHeaderOffset = rightTreeViewer.getTree().getHeaderHeight(); + } + boolean rightItemVisible = true; TreeItem rightTreeItem = (TreeItem) rightTreeViewer.testFindItem(semanticSupport.resolveRightItem(mapping)); if (rightTreeItem == null) { @@ -388,7 +398,7 @@ private boolean drawMapping(final M mapping) { } rightTreeItem = rightTreeItem.getParentItem(); } - arrowFigure.setRightPoint(linkRootFigure.getBounds().width, lastVisibleRightTreeItem.getBounds().y + rightTreeItem.getBounds().height / 2); + arrowFigure.setRightPoint(linkRootFigure.getBounds().width, rightHeaderOffset + lastVisibleRightTreeItem.getBounds().y + rightTreeItem.getBounds().height / 2); arrowFigure.setRightMappingVisible(rightItemVisible); } From b900123da4628bcfa31fae3df042192a44f17b72 Mon Sep 17 00:00:00 2001 From: Gionata Boccalini Date: Sun, 28 Jan 2024 19:23:04 +0100 Subject: [PATCH 5/6] Add public method to update canvas draw Add public method to request the canvas mapping to be redrawn. Add canvasNeedRedraw flag reset on left tree scroll listener. --- .../eclipse/nebula/widgets/treemapper/TreeMapper.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java index 627981b1b..35a2be4f8 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper/src/org/eclipse/nebula/widgets/treemapper/TreeMapper.java @@ -143,6 +143,7 @@ public void controlMoved(ControlEvent e) { if (canvasNeedRedraw || leftTreeViewer.getTree().getTopItem() != leftTopItem) { leftTopItem = leftTreeViewer.getTree().getTopItem(); redrawMappings(); + canvasNeedRedraw = false; } }); rightTreeViewer.getTree().addListener(SWT.Paint, e -> { @@ -625,6 +626,14 @@ public void refresh() { canvasNeedRedraw = true; control.layout(true); } + + /** + * Force canvas update and redraw + */ + public void updateCanvas() { + canvasNeedRedraw = true; + redrawMappings(); + } /** * From 56c511ad5b6588062d81c0cffabaad62e98b5be3 Mon Sep 17 00:00:00 2001 From: Gionata Boccalini Date: Sun, 28 Jan 2024 19:33:14 +0100 Subject: [PATCH 6/6] Add signalOnMissingItem implementation fo tests and examples. --- .../examples/DOMSemanticTreeMapperSupport.java | 8 ++++++++ .../widgets/treemapper/tests/ObjectSemanticSupport.java | 9 ++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.examples/src/org/eclipse/nebula/widgets/treemapper/examples/DOMSemanticTreeMapperSupport.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.examples/src/org/eclipse/nebula/widgets/treemapper/examples/DOMSemanticTreeMapperSupport.java index f1341b99c..2ca7e4f94 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.examples/src/org/eclipse/nebula/widgets/treemapper/examples/DOMSemanticTreeMapperSupport.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.examples/src/org/eclipse/nebula/widgets/treemapper/examples/DOMSemanticTreeMapperSupport.java @@ -54,4 +54,12 @@ public Node resolveLeftItem(DOMMappingBean semanticMappingObject) { public Node resolveRightItem(DOMMappingBean semanticMappingObject) { return semanticMappingObject.right; } + + /** + * @see org.eclipse.nebula.treemapper.ISemanticTreeMapperSupport#signalOnMissingItem() + */ + @Override + public boolean signalOnMissingItem() { + return true; + } } diff --git a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.tests/src/org/eclipse/nebula/widgets/treemapper/tests/ObjectSemanticSupport.java b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.tests/src/org/eclipse/nebula/widgets/treemapper/tests/ObjectSemanticSupport.java index 326dfefcc..9c2cb5144 100644 --- a/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.tests/src/org/eclipse/nebula/widgets/treemapper/tests/ObjectSemanticSupport.java +++ b/widgets/treemapper/org.eclipse.nebula.widgets.treemapper.tests/src/org/eclipse/nebula/widgets/treemapper/tests/ObjectSemanticSupport.java @@ -44,5 +44,12 @@ public String resolveLeftItem(String semanticMappingObject) { public String resolveRightItem(String semanticMappingObject) { return semanticMappingObject; } - + + /** + * @see org.eclipse.nebula.treemapper.ISemanticTreeMapperSupport#signalOnMissingItem() + */ + @Override + public boolean signalOnMissingItem() { + return true; + } }