use of com.structurizr.model.CustomElement in project dsl by structurizr.
the class CustomElementParserTests method test_parse_CreatesACustomElement.
@Test
void test_parse_CreatesACustomElement() {
parser.parse(context(), tokens("element", "Name"));
assertEquals(1, model.getElements().size());
CustomElement element = model.getCustomElementWithName("Name");
assertNotNull(element);
assertEquals("", element.getDescription());
assertEquals("Element", element.getTags());
}
use of com.structurizr.model.CustomElement in project dsl by structurizr.
the class CustomElementParserTests method test_parse_CreatesACustomElementWithMetadataAndDescription.
@Test
void test_parse_CreatesACustomElementWithMetadataAndDescription() {
parser.parse(context(), tokens("element", "Name", "Box", "Description"));
assertEquals(1, model.getElements().size());
CustomElement element = model.getCustomElementWithName("Name");
assertNotNull(element);
assertEquals("Box", element.getMetadata());
assertEquals("Description", element.getDescription());
assertEquals("Element", element.getTags());
}
use of com.structurizr.model.CustomElement in project dsl by structurizr.
the class CustomElementParserTests method test_parse_CreatesACustomElementWithMetadataAndDescriptionAndTags.
@Test
void test_parse_CreatesACustomElementWithMetadataAndDescriptionAndTags() {
parser.parse(context(), tokens("element", "Name", "Box", "Description", "Tag 1, Tag 2"));
assertEquals(1, model.getElements().size());
CustomElement element = model.getCustomElementWithName("Name");
assertNotNull(element);
assertEquals("Box", element.getMetadata());
assertEquals("Description", element.getDescription());
assertEquals("Element,Tag 1,Tag 2", element.getTags());
}
use of com.structurizr.model.CustomElement in project dsl by structurizr.
the class CustomElementParser method parse.
CustomElement parse(GroupableDslContext context, Tokens tokens) {
if (tokens.hasMoreThan(TAGS_INDEX)) {
throw new RuntimeException("Too many tokens, expected: " + GRAMMAR);
}
if (!tokens.includes(NAME_INDEX)) {
throw new RuntimeException("Expected: " + GRAMMAR);
}
String name = tokens.get(NAME_INDEX);
String metadata = "";
if (tokens.includes(METADATA_INDEX)) {
metadata = tokens.get(METADATA_INDEX);
}
String description = "";
if (tokens.includes(DESCRIPTION_INDEX)) {
description = tokens.get(DESCRIPTION_INDEX);
}
CustomElement customElement = context.getWorkspace().getModel().addCustomElement(name, metadata, description);
if (tokens.includes(TAGS_INDEX)) {
String tags = tokens.get(TAGS_INDEX);
customElement.addTags(tags.split(","));
}
if (context.hasGroup()) {
customElement.setGroup(context.getGroup().getName());
}
return customElement;
}
use of com.structurizr.model.CustomElement in project java by structurizr.
the class CustomView method addAnimation.
/**
* Adds an animation step, with the specified elements.
*
* @param elements the elements that should be shown in the animation step
*/
public void addAnimation(CustomElement... elements) {
if (elements == null || elements.length == 0) {
throw new IllegalArgumentException("One or more elements must be specified.");
}
Set<String> elementIdsInPreviousAnimationSteps = new HashSet<>();
for (Animation animationStep : animations) {
elementIdsInPreviousAnimationSteps.addAll(animationStep.getElements());
}
Set<Element> elementsInThisAnimationStep = new HashSet<>();
Set<Relationship> relationshipsInThisAnimationStep = new HashSet<>();
for (CustomElement element : elements) {
if (isElementInView(element)) {
if (!elementIdsInPreviousAnimationSteps.contains(element.getId())) {
elementIdsInPreviousAnimationSteps.add(element.getId());
elementsInThisAnimationStep.add(element);
}
}
}
if (elementsInThisAnimationStep.size() == 0) {
throw new IllegalArgumentException("None of the specified elements exist in this view.");
}
for (RelationshipView relationshipView : this.getRelationships()) {
if ((elementsInThisAnimationStep.contains(relationshipView.getRelationship().getSource()) && elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getDestination().getId())) || (elementIdsInPreviousAnimationSteps.contains(relationshipView.getRelationship().getSource().getId()) && elementsInThisAnimationStep.contains(relationshipView.getRelationship().getDestination()))) {
relationshipsInThisAnimationStep.add(relationshipView.getRelationship());
}
}
animations.add(new Animation(animations.size() + 1, elementsInThisAnimationStep, relationshipsInThisAnimationStep));
}
Aggregations