Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » GEF5 Node building(Trying to build nodes as words of a sentence)
GEF5 Node building [message #1767070] Fri, 30 June 2017 11:18 Go to next message
Mike Shimko is currently offline Mike ShimkoFriend
Messages: 9
Registered: May 2017
Location: Moscow
Junior Member
Im trying to make such scenario:

1.User enters a sentence in UI and presses a button
2.Sentence is converted to tokens
tokens = str.split(delims);

3.Graph is being created
static Graph createGraph() {
		Builder b = new Graph.Builder();
		addNodes(b,1);
		Graph g = b.build();
		System.out.println(g);
		return g;
	}
addNodes method:
private static void addNodes(Graph.Builder graphBuilder,int startNumber) {
	List<Node> nodes = new ArrayList<>();
	for (int i = 0; i < tokens.length; i++) {
		nodes.add(new Node.Builder().attr(tokens[i], (startNumber + i)).buildNode());
	}
	graphBuilder.nodes(nodes);
}

4. Graph set to Iviewer
viewer.getContents().setAll(Collections.singletonList(graph));


It does work, however:
1.node names are not displayed ( how to add token as a node name?)
2.all nodes are overlapping eachother ( layoutAlgorithm is missing i guess)

Any ways of correcting my code? Maybe there is other way to build nodes of a graph when sentence size is variable?

UPD: Fixed the overlapping with adding LayoutAlgorithm
.attr(ZestProperties.LAYOUT_ALGORITHM__G,new HorizontalShiftAlgorithm());

UPD 2:
Fixed names using simplier builder for nodes
static Graph createGraph() {
		Builder b = new Graph.Builder()
			.attr(ZestProperties.LAYOUT_ALGORITHM__G,new HorizontalShiftAlgorithm());
		for (int i = 0; i < tokens.length; i++) {
			b.node(tokens[i]).attr(LABEL, tokens[i]);
		}
		Graph g = b.build();
		System.out.println(g);
		return g;
	}

Case closed :P

[Updated on: Fri, 30 June 2017 12:23]

Report message to a moderator

Re: GEF5 Node building [message #1767076 is a reply to message #1767070] Fri, 30 June 2017 12:23 Go to previous messageGo to next message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 163
Registered: March 2015
Senior Member
Hi Mike,

1) You need to set the correct attribute when creating the nodes, for the label it is ZestProperties#LABEL__NE.
2) You can specify the layout algorithm via the ZestProperties#LAYOUT_ALGORITHM__G attribute.

Simple example:
    public Graph buildForSentence(String sentence) {
        Builder b = new Graph.Builder();
        b.attr(ZestProperties.LAYOUT_ALGORITHM__G, new GridLayoutAlgorithm());
        String[] words = sentence.split(" ");
        for (int i = 0; i < words.length; i++) {
            b.node(i).attr(ZestProperties.LABEL__NE, words[i]);
            if (i > 0) {
                b.edge(i - 1, i).attr(ZestProperties.TARGET_DECORATION__E, new Polygon(-10, 0, 0, 5, 0, -5));
            }
        }
        return b.build();
    }

    @Override
    protected Graph createGraph() {
        String sentence = "The quick brown fox jumps over the lazy dog.";
        return buildForSentence(sentence);
    }

Note that you can assign a key to the nodes during construction, to which you can refer to add edges or attributes later.

Best regards,
Matthias
Re: GEF5 Node building [message #1767081 is a reply to message #1767076] Fri, 30 June 2017 13:08 Go to previous message
Mike Shimko is currently offline Mike ShimkoFriend
Messages: 9
Registered: May 2017
Location: Moscow
Junior Member
Thank you!
Previous Topic:JavaFX + GEF5 + E4 RCP Application troubles
Next Topic:JavaFX + GEF5 + E4 RCP. EventHandling
Goto Forum:
  


Current Time: Wed Sep 19 05:37:16 GMT 2018

Powered by FUDForum. Page generated in 0.01968 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top