Home » Eclipse Projects » GEF » Resize a GEF4 ZestFxUiView move all nodes
Resize a GEF4 ZestFxUiView move all nodes [message #1718637] |
Mon, 28 December 2015 13:48 |
Victor Hiairrassary Messages: 7 Registered: December 2015 |
Junior Member |
|
|
Hello,
If I manually resize a ZestFxUiView then all nodes from the graph are moved (confirmed by logging locations). Here is a GIF that illustrate it : g.recordit.co/ISWotaPhVb.gif
I have tried to use a empty layout algorithm and to add ".attr(ZestProperties.ELEMENT_LAYOUT_IRRELEVANT, true)" to
the node & edge builders. Regarding my last try I think the issue is not tied to layouts.
Here is my code :
package gef4test.views;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import org.eclipse.gef4.graph.Edge;
import org.eclipse.gef4.graph.Graph;
import org.eclipse.gef4.graph.Node;
import org.eclipse.gef4.layout.*;
import org.eclipse.gef4.zest.fx.ZestProperties;
import org.eclipse.gef4.zest.fx.ui.parts.ZestFxUiView;
public class SampleView extends ZestFxUiView {
public SampleView() {
setGraph(createDefaultGraph());
}
private static int id = 0;
protected static String genId() {
return Integer.toString(id++);
}
protected static final String ID = ZestProperties.ELEMENT_CSS_ID;
protected static final String LABEL = ZestProperties.ELEMENT_LABEL;
protected static Edge e(org.eclipse.gef4.graph.Node n,
org.eclipse.gef4.graph.Node m, Object... attr) {
String label = (String) n.getAttrs().get(LABEL)
+ (String) m.getAttrs().get(LABEL);
Edge.Builder builder = new Edge.Builder(n, m).attr(LABEL, label).attr(ID,
genId());
for (int i = 0; i < attr.length; i += 2) {
builder.attr(attr[i].toString(), attr[i + 1]);
}
return builder.build();
}
protected static org.eclipse.gef4.graph.Node n(Object... attr) {
org.eclipse.gef4.graph.Node.Builder builder = new org.eclipse.gef4.graph.Node.Builder();
String id = genId();
builder.attr(ID, id).attr(LABEL, id);
for (int i = 0; i < attr.length; i += 2) {
builder.attr(attr[i].toString(), attr[i + 1]);
}
return builder.build();
}
public static Graph createDefaultGraph() {
// create nodes "0" to "9"
List<org.eclipse.gef4.graph.Node> nodes = new ArrayList<>();
nodes.addAll(Arrays.asList(n(ZestProperties.ELEMENT_LABEL, "0", ZestProperties.NODE_TOOLTIP, "zero"),
n(ZestProperties.ELEMENT_LABEL, "1", ZestProperties.NODE_TOOLTIP, "one"),
n(ZestProperties.ELEMENT_LABEL, "2", ZestProperties.NODE_TOOLTIP, "two"),
n(ZestProperties.ELEMENT_LABEL, "3", ZestProperties.NODE_TOOLTIP, "three"),
n(ZestProperties.ELEMENT_LABEL, "4", ZestProperties.NODE_TOOLTIP, "four"),
n(ZestProperties.ELEMENT_LABEL, "5", ZestProperties.NODE_TOOLTIP, "five"),
n(ZestProperties.ELEMENT_LABEL, "6", ZestProperties.NODE_TOOLTIP, "six"),
n(ZestProperties.ELEMENT_LABEL, "7", ZestProperties.NODE_TOOLTIP, "seven"),
n(ZestProperties.ELEMENT_LABEL, "8", ZestProperties.NODE_TOOLTIP, "eight"),
n(ZestProperties.ELEMENT_LABEL, "9", ZestProperties.NODE_TOOLTIP, "nine")));
// create some edges between those nodes
List<Edge> edges = new ArrayList<>();
edges.addAll(Arrays.asList(e(nodes.get(0), nodes.get(9)), e(nodes.get(1), nodes.get(8)),
e(nodes.get(2), nodes.get(7)), e(nodes.get(3), nodes.get(6)), e(nodes.get(4), nodes.get(5)),
e(nodes.get(0), nodes.get(4)), e(nodes.get(1), nodes.get(6)), e(nodes.get(2), nodes.get(8)),
e(nodes.get(3), nodes.get(5)), e(nodes.get(4), nodes.get(7)), e(nodes.get(5), nodes.get(1))));
// directed connections
HashMap<String, Object> attrs = new HashMap<>();
attrs.put(ZestProperties.GRAPH_TYPE, ZestProperties.GRAPH_TYPE_DIRECTED);
attrs.put(ZestProperties.GRAPH_LAYOUT, new ManualLayoutAlgorithm());
return new Graph(attrs, nodes, edges);
}
public static class ManualLayoutAlgorithm implements ILayoutAlgorithm {
private ILayoutContext ctx;
public void setLayoutContext(ILayoutContext context) { ctx = context; }
public ILayoutContext getLayoutContext() { return ctx; }
public void applyLayout(boolean clean) {}
}
}
BTW, I use a mac with Oracle JVM 1.8 & I was able to reproduced the issue with 0.2.0 release and latest 0.3.0 milestone from http://download.eclipse.org/tools/gef/gef4/updates/milestones
Thank you in advance,
Victor
P.S. I have previously asked this on the GEF mailing list, but I found it was no the right place.
|
|
|
Re: Resize a GEF4 ZestFxUiView move all nodes [message #1718691 is a reply to message #1718637] |
Tue, 29 December 2015 09:39 |
|
This behavior is implemented in LayoutContexBehavior. By default, it re-applies layout whenever the viewport bounds are changed. You can replace it with a custom implementation (i.e. bind another implementation in a module that extends or overrides the ZestFxModule) that overwrites onViewportModelPropertyChange(Bounds, Bounds) to only initialize the layout bounds once, not on every viewport bounds change:
protected void onViewportModelPropertyChange(Bounds oldScrollableBounds, Bounds newScrollableBounds) {
InfiniteCanvas canvas = getInfiniteCanvas();
Rectangle newBounds = new Rectangle(0, 0, canvas.getWidth(), canvas.getHeight());
if (LayoutProperties.getBounds(layoutContext).isEmpty()) {
LayoutProperties.setBounds(layoutContext, newBounds);
}
}
|
|
| |
Re: Resize a GEF4 ZestFxUiView move all nodes [message #1718721 is a reply to message #1718694] |
Tue, 29 December 2015 12:38 |
|
If you extend a Guice module (and not override it using Modules.override()) you do not overwrite (i.e. redefine) the module's bindings. In this concrete case, the call to super.bindGraphContentPartAdapters() will thus lead to conflicting bindings (those defined by the super module and those defined by your module). To enable that clients can overwrite individual bindings while only extending the ZestFxModule (but not overriding it) we should probably provide each binding in a separate method (as e.g. done within MvcFxModule), which can then be overwritten individually. I have raised https://bugs.eclipse.org/bugs/show_bug.cgi?id=484972 to keep track of this.
|
|
|
Goto Forum:
Current Time: Wed Sep 25 15:15:32 GMT 2024
Powered by FUDForum. Page generated in 0.06553 seconds
|