Skip to content
This repository was archived by the owner on Mar 28, 2026. It is now read-only.

Commit cfa3287

Browse files
Adds support for custom elements on dynamic views.
1 parent 23d3921 commit cfa3287

8 files changed

Lines changed: 135 additions & 36 deletions

File tree

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ subprojects { proj ->
88

99
description = 'Structurizr'
1010
group = 'com.structurizr'
11-
version = '1.14.2'
11+
version = '1.15.0'
1212

1313
repositories {
1414
mavenCentral()

docs/changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Changelog
22

3-
## 1.14.2 (unreleased to Maven Central)
3+
## 1.15.0 (unreleased to Maven Central)
44

55
- Adds documentation section filenames into the model.
6+
- Adds support for custom elements on dynamic views.
67

78
## 1.14.1 (15th August 2022)
89

structurizr-core/src/com/structurizr/view/CustomView.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,34 @@ void setAnimations(List<Animation> animations) {
136136
}
137137
}
138138

139+
/**
140+
* Adds the given custom element to this view, including relationships to/from that custom element.
141+
*
142+
* @param customElement the CustomElement to add
143+
*/
144+
public void add(@Nonnull CustomElement customElement) {
145+
add(customElement, true);
146+
}
147+
148+
/**
149+
* Adds the given custom element to this view.
150+
*
151+
* @param customElement the CustomElement to add
152+
* @param addRelationships whether to add relationships to/from the custom element
153+
*/
154+
public void add(@Nonnull CustomElement customElement, boolean addRelationships) {
155+
addElement(customElement, addRelationships);
156+
}
157+
158+
/**
159+
* Removes the given custom element from this view.
160+
*
161+
* @param customElement the CustomElement to add
162+
*/
163+
public void remove(@Nonnull CustomElement customElement) {
164+
removeElement(customElement);
165+
}
166+
139167
/**
140168
* Adds the default set of elements to this view.
141169
*/

structurizr-core/src/com/structurizr/view/DeploymentView.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,4 +451,32 @@ void setAnimations(List<Animation> animations) {
451451
}
452452
}
453453

454+
/**
455+
* Adds the given custom element to this view, including relationships to/from that custom element.
456+
*
457+
* @param customElement the CustomElement to add
458+
*/
459+
public void add(@Nonnull CustomElement customElement) {
460+
add(customElement, true);
461+
}
462+
463+
/**
464+
* Adds the given custom element to this view.
465+
*
466+
* @param customElement the CustomElement to add
467+
* @param addRelationships whether to add relationships to/from the custom element
468+
*/
469+
public void add(@Nonnull CustomElement customElement, boolean addRelationships) {
470+
addElement(customElement, addRelationships);
471+
}
472+
473+
/**
474+
* Removes the given custom element from this view.
475+
*
476+
* @param customElement the CustomElement to add
477+
*/
478+
public void remove(@Nonnull CustomElement customElement) {
479+
removeElement(customElement);
480+
}
481+
454482
}

structurizr-core/src/com/structurizr/view/DynamicView.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,46 @@ public RelationshipView add(@Nonnull StaticStructureElement source, String descr
100100
}
101101

102102
public RelationshipView add(@Nonnull StaticStructureElement source, String description, String technology, @Nonnull StaticStructureElement destination) {
103+
return addRelationshipViaElements(source, description, technology, destination);
104+
}
105+
106+
public RelationshipView add(@Nonnull CustomElement source, @Nonnull StaticStructureElement destination) {
107+
return add(source, "", destination);
108+
}
109+
110+
public RelationshipView add(@Nonnull CustomElement source, String description, @Nonnull StaticStructureElement destination) {
111+
return add(source, description, "", destination);
112+
}
113+
114+
public RelationshipView add(@Nonnull CustomElement source, String description, String technology, @Nonnull StaticStructureElement destination) {
115+
return addRelationshipViaElements(source, description, technology, destination);
116+
}
117+
118+
public RelationshipView add(@Nonnull StaticStructureElement source, @Nonnull CustomElement destination) {
119+
return add(source, "", destination);
120+
}
121+
122+
public RelationshipView add(@Nonnull StaticStructureElement source, String description, @Nonnull CustomElement destination) {
123+
return add(source, description, "", destination);
124+
}
125+
126+
public RelationshipView add(@Nonnull StaticStructureElement source, String description, String technology, @Nonnull CustomElement destination) {
127+
return addRelationshipViaElements(source, description, technology, destination);
128+
}
129+
130+
public RelationshipView add(@Nonnull CustomElement source, @Nonnull CustomElement destination) {
131+
return add(source, "", destination);
132+
}
133+
134+
public RelationshipView add(@Nonnull CustomElement source, String description, @Nonnull CustomElement destination) {
135+
return add(source, description, "", destination);
136+
}
137+
138+
public RelationshipView add(@Nonnull CustomElement source, String description, String technology, @Nonnull CustomElement destination) {
139+
return addRelationshipViaElements(source, description, technology, destination);
140+
}
141+
142+
private RelationshipView addRelationshipViaElements(@Nonnull Element source, String description, String technology, @Nonnull Element destination) {
103143
if (source == null) {
104144
throw new IllegalArgumentException("A source element must be specified.");
105145
}
@@ -244,6 +284,11 @@ public void endParallelSequence(boolean endAllParallelSequencesAndContinueNumber
244284

245285
@Override
246286
protected void checkElementCanBeAdded(Element elementToBeAdded) {
287+
if (elementToBeAdded instanceof CustomElement) {
288+
// all good
289+
return;
290+
}
291+
247292
if (!(elementToBeAdded instanceof StaticStructureElement)) {
248293
throw new ElementNotPermittedInViewException("Only people, software systems, containers and components can be added to dynamic views.");
249294
}

structurizr-core/src/com/structurizr/view/StaticView.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.structurizr.view;
22

3-
import com.structurizr.model.Element;
4-
import com.structurizr.model.Person;
5-
import com.structurizr.model.Relationship;
6-
import com.structurizr.model.SoftwareSystem;
3+
import com.structurizr.model.*;
74

85
import javax.annotation.Nonnull;
96
import java.util.ArrayList;
@@ -240,4 +237,32 @@ void setAnimations(List<Animation> animations) {
240237
}
241238
}
242239

240+
/**
241+
* Adds the given custom element to this view, including relationships to/from that custom element.
242+
*
243+
* @param customElement the CustomElement to add
244+
*/
245+
public void add(@Nonnull CustomElement customElement) {
246+
add(customElement, true);
247+
}
248+
249+
/**
250+
* Adds the given custom element to this view.
251+
*
252+
* @param customElement the CustomElement to add
253+
* @param addRelationships whether to add relationships to/from the custom element
254+
*/
255+
public void add(@Nonnull CustomElement customElement, boolean addRelationships) {
256+
addElement(customElement, addRelationships);
257+
}
258+
259+
/**
260+
* Removes the given custom element from this view.
261+
*
262+
* @param customElement the CustomElement to add
263+
*/
264+
public void remove(@Nonnull CustomElement customElement) {
265+
removeElement(customElement);
266+
}
267+
243268
}

structurizr-core/src/com/structurizr/view/View.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -510,25 +510,6 @@ final void checkParentAndChildrenHaveNotAlreadyBeenAdded(StaticStructureElement
510510
}
511511
}
512512

513-
/**
514-
* Adds the given custom element to this view, including relationships to/from that custom element.
515-
*
516-
* @param customElement the CustomElement to add
517-
*/
518-
public void add(@Nonnull CustomElement customElement) {
519-
add(customElement, true);
520-
}
521-
522-
/**
523-
* Adds the given custom element to this view.
524-
*
525-
* @param customElement the CustomElement to add
526-
* @param addRelationships whether to add relationships to/from the custom element
527-
*/
528-
public void add(@Nonnull CustomElement customElement, boolean addRelationships) {
529-
addElement(customElement, addRelationships);
530-
}
531-
532513
protected <T extends Element> void addNearestNeighbours(Element element, Class<T> typeOfElement) {
533514
if (element == null) {
534515
return;
@@ -562,13 +543,4 @@ protected <T extends Element> void addNearestNeighbours(Element element, Class<T
562543
}
563544
}
564545

565-
/**
566-
* Removes the given custom element from this view.
567-
*
568-
* @param customElement the CustomElement to add
569-
*/
570-
public void remove(@Nonnull CustomElement customElement) {
571-
removeElement(customElement);
572-
}
573-
574546
}

structurizr-core/test/unit/com/structurizr/view/DynamicViewTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public void setup() {
4747
void add_ThrowsAnException_WhenPassedANullSourceElement() {
4848
try {
4949
DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description");
50-
dynamicView.add(null, softwareSystemA);
50+
dynamicView.add((StaticStructureElement)null, softwareSystemA);
5151
fail();
5252
} catch (IllegalArgumentException iae) {
5353
assertEquals("A source element must be specified.", iae.getMessage());
@@ -58,7 +58,7 @@ void add_ThrowsAnException_WhenPassedANullSourceElement() {
5858
void add_ThrowsAnException_WhenPassedANullDestinationElement() {
5959
try {
6060
DynamicView dynamicView = workspace.getViews().createDynamicView("key", "Description");
61-
dynamicView.add(person, null);
61+
dynamicView.add(person, (StaticStructureElement)null);
6262
fail();
6363
} catch (IllegalArgumentException iae) {
6464
assertEquals("A destination element must be specified.", iae.getMessage());

0 commit comments

Comments
 (0)