Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treemapper general usability improvements #561

Merged
merged 6 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,10 @@ public interface ISemanticTreeMapperSupport<M, L, R> {
* @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();
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand All @@ -164,10 +165,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);
}
}

/**
Expand Down Expand Up @@ -340,15 +343,23 @@ 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) {
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) {
Expand All @@ -358,19 +369,27 @@ 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) {
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) {
Expand All @@ -380,7 +399,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);
}

Expand Down Expand Up @@ -607,6 +626,14 @@ public void refresh() {
canvasNeedRedraw = true;
control.layout(true);
}

/**
* Force canvas update and redraw
*/
public void updateCanvas() {
canvasNeedRedraw = true;
redrawMappings();
}

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,23 @@ 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;
}


public TreeMapperUIConfigProvider(Color defaultColor, int defaultWidth, Color selectedColor, int selectedWidth) {
this(defaultColor, defaultWidth, selectedColor, selectedWidth, new int[] { 1, 2, 1});
}

/**
* @return
*/
Expand Down Expand Up @@ -64,4 +74,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;
}
}
Loading