Skip to content

Commit a20599e

Browse files
committed
feat: add methods to edit the chart by adding, editing and removing nodes
New API includes methods to add siblings, add children, add parent, update and remove nodes. Close #78
1 parent 6c7ac0b commit a20599e

File tree

10 files changed

+1339
-16
lines changed

10 files changed

+1339
-16
lines changed

src/main/java/com/flowingcode/vaadin/addons/orgchart/OrgChart.java

Lines changed: 401 additions & 15 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2025 Flowing Code S.A.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart.event;
21+
22+
import com.flowingcode.vaadin.addons.orgchart.OrgChart;
23+
import com.flowingcode.vaadin.addons.orgchart.OrgChartItem;
24+
import com.vaadin.flow.component.ComponentEvent;
25+
import java.util.ArrayList;
26+
import java.util.List;
27+
28+
/**
29+
* Event fired when children are added to a node in the organization chart. Contains information
30+
* about both the parent node and the newly added children.
31+
*/
32+
@SuppressWarnings("serial")
33+
public class ChildrenAddedEvent extends ComponentEvent<OrgChart> {
34+
private final OrgChartItem item;
35+
private final List<OrgChartItem> newChildren;
36+
37+
/**
38+
* Creates a new children added event.
39+
*
40+
* @param source the chart component that fired the event
41+
* @param item the node that received new children
42+
* @param newChildren list of the newly added children
43+
* @param fromClient whether the event originated from the client side
44+
*/
45+
public ChildrenAddedEvent(OrgChart source, OrgChartItem item, List<OrgChartItem> newChildren,
46+
boolean fromClient) {
47+
super(source, fromClient);
48+
this.item = item;
49+
this.newChildren = new ArrayList<>(newChildren);
50+
}
51+
52+
/**
53+
* Gets the node that received new children.
54+
*
55+
* @return the node
56+
*/
57+
public OrgChartItem getItem() {
58+
return item;
59+
}
60+
61+
/**
62+
* Gets the list of the newly added children.
63+
*
64+
* @return the list of new children
65+
*/
66+
public List<OrgChartItem> getNewChildren() {
67+
return newChildren;
68+
}
69+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.flowingcode.vaadin.addons.orgchart.event;
2+
3+
import com.flowingcode.vaadin.addons.orgchart.OrgChart;
4+
import com.flowingcode.vaadin.addons.orgchart.OrgChartItem;
5+
import com.vaadin.flow.component.ComponentEvent;
6+
7+
8+
/**
9+
* Event thrown when a node is updated.
10+
*/
11+
@SuppressWarnings("serial")
12+
public class NodeUpdatedEvent extends ComponentEvent<OrgChart> {
13+
private final OrgChartItem updatedItem;
14+
15+
/**
16+
* Creates a node updated event.
17+
*
18+
* @param source the chart component that fired the event
19+
* @param updatedItem the node being updated
20+
* @param fromClient whether the event originated from the client side
21+
*/
22+
public NodeUpdatedEvent(OrgChart source, OrgChartItem updatedItem, boolean fromClient) {
23+
super(source, fromClient);
24+
this.updatedItem = updatedItem;
25+
}
26+
27+
/**
28+
* Gets the updated node.
29+
*
30+
* @return the updated node item
31+
*/
32+
public OrgChartItem getUpdatedItem() {
33+
return updatedItem;
34+
}
35+
36+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2025 Flowing Code S.A.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart.event;
21+
22+
import com.flowingcode.vaadin.addons.orgchart.OrgChart;
23+
import com.vaadin.flow.component.ComponentEvent;
24+
25+
/**
26+
* Event fired when a node and its descendants are removed from the organization chart. Contains
27+
* information about the removed node.
28+
*/
29+
@SuppressWarnings("serial")
30+
public class NodesRemovedEvent extends ComponentEvent<OrgChart> {
31+
private final Integer nodeId;
32+
33+
/**
34+
* Creates a new nodes removed event.
35+
*
36+
* @param source the chart component that fired the event
37+
* @param nodeId the ID of the removed node
38+
* @param fromClient whether the event originated from the client side
39+
*/
40+
public NodesRemovedEvent(OrgChart source, Integer nodeId, boolean fromClient) {
41+
super(source, fromClient);
42+
this.nodeId = nodeId;
43+
}
44+
45+
/**
46+
* Gets the ID of the removed node.
47+
*
48+
* @return the node ID
49+
*/
50+
public Integer getNodeId() {
51+
return nodeId;
52+
}
53+
54+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2025 Flowing Code S.A.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart.event;
21+
22+
import com.flowingcode.vaadin.addons.orgchart.OrgChart;
23+
import com.flowingcode.vaadin.addons.orgchart.OrgChartItem;
24+
import com.vaadin.flow.component.ComponentEvent;
25+
26+
/**
27+
* Event fired when a new parent is added to the chart.
28+
*/
29+
@SuppressWarnings("serial")
30+
public class ParentAddedEvent extends ComponentEvent<OrgChart> {
31+
32+
private final OrgChartItem newParent;
33+
34+
/**
35+
* Creates a new event.
36+
*
37+
* @param source the component that fired the event
38+
* @param newParent the item that was added as the new parent
39+
* @param fromClient true if the event originated from the client
40+
*/
41+
public ParentAddedEvent(OrgChart source, OrgChartItem newParent, boolean fromClient) {
42+
super(source, fromClient);
43+
this.newParent = newParent;
44+
}
45+
46+
/**
47+
* Gets the item that was added as the new parent/root.
48+
*
49+
* @return the new parent item
50+
*/
51+
public OrgChartItem getNewParent() {
52+
return newParent;
53+
}
54+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*-
2+
* #%L
3+
* OrgChart Add-on
4+
* %%
5+
* Copyright (C) 2017 - 2025 Flowing Code S.A.
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.orgchart.event;
21+
22+
import java.util.ArrayList;
23+
import java.util.List;
24+
25+
import com.flowingcode.vaadin.addons.orgchart.OrgChart;
26+
import com.flowingcode.vaadin.addons.orgchart.OrgChartItem;
27+
import com.vaadin.flow.component.ComponentEvent;
28+
29+
/**
30+
* Event fired when siblings are added to a node in the organization chart. Contains information
31+
* about both the target node and the newly added siblings.
32+
*/
33+
@SuppressWarnings("serial")
34+
public class SiblingsAddedEvent extends ComponentEvent<OrgChart> {
35+
private final OrgChartItem item;
36+
private final List<OrgChartItem> newSiblings;
37+
38+
/**
39+
* Creates a new siblings added event.
40+
*
41+
* @param source the chart component that fired the event
42+
* @param item the node that received new siblings
43+
* @param newSiblings list of the newly added siblings
44+
* @param fromClient whether the event originated from the client side
45+
*/
46+
public SiblingsAddedEvent(OrgChart source, OrgChartItem item, List<OrgChartItem> newSiblings,
47+
boolean fromClient) {
48+
super(source, fromClient);
49+
this.item = item;
50+
this.newSiblings = new ArrayList<>(newSiblings);
51+
}
52+
53+
/**
54+
* Gets the node that received new siblings.
55+
*
56+
* @return the node
57+
*/
58+
public OrgChartItem getItem() {
59+
return item;
60+
}
61+
62+
/**
63+
* Gets the list of the newly added siblings.
64+
*
65+
* @return the list of new sibling
66+
*/
67+
public List<OrgChartItem> getNewSiblings() {
68+
return newSiblings;
69+
}
70+
}

0 commit comments

Comments
 (0)