Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Adds a "default" keyword, for setting the default view.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Feb 18, 2023
1 parent 567fe9c commit 06c6b3a
Show file tree
Hide file tree
Showing 12 changed files with 129 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 1.26.1 (18th February 2023)

- Sets titles for image view content specified via URLs.
- Adds a `default` keyword, for setting the default view.

## 1.26.0 (17th February 2023)

Expand Down
26 changes: 25 additions & 1 deletion docs/language-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -981,6 +981,7 @@ Permitted children:
- [include](#include)
- [exclude](#exclude)
- [autoLayout](#autoLayout)
- [default](#default)
- [animation](#animation)
- [title](#title)
- [description](#description)
Expand All @@ -1003,6 +1004,7 @@ Permitted children:
- [include](#include)
- [exclude](#exclude)
- [autoLayout](#autoLayout)
- [default](#default)
- [animation](#animation)
- [title](#title)
- [description](#description)
Expand All @@ -1025,6 +1027,7 @@ Permitted children:
- [include](#include)
- [exclude](#exclude)
- [autoLayout](#autoLayout)
- [default](#default)
- [animation](#animation)
- [title](#title)
- [description](#description)
Expand All @@ -1047,6 +1050,7 @@ Permitted children:
- [include](#include)
- [exclude](#exclude)
- [autoLayout](#autoLayout)
- [default](#default)
- [animation](#animation)
- [title](#title)
- [description](#description)
Expand All @@ -1057,13 +1061,22 @@ Permitted children:
The `filtered` keyword is used to define a [Filtered view](https://structurizr.com/help/filtered-views) on top of the specified view.

```
filtered <baseKey> <include|exclude> <tags> [key] [description]
filtered <baseKey> <include|exclude> <tags> [key] [description] {
...
}
```

The `baseKey` specifies the key of the System Landscape, System Context, Container, or Component view on which this filtered view should be based. The mode (`include` or `exclude`) defines whether the view should include or exclude elements/relationships based upon the `tags` provided.

Please note that once a filtered view is defined for a given "base view", that base view will no longer show up in your diagram list when using the Structurizr renderer. This is by design. If you'd like to see the base view too, just create another filtered view for the same base view, which includes the `Element` and `Relationship` tags.

Permitted children:

- [default](#default)
- [title](#title)
- [description](#description)
- [properties](#properties)

```
filtered <baseKey> include "Element,Relationship" [key] [description]
```
Expand Down Expand Up @@ -1100,6 +1113,7 @@ See [parallel.dsl](../src/test/dsl/parallel.dsl) for an example of how to create
Permitted children:

- [autoLayout](#autoLayout)
- [default](#default)
- [title](#title)
- [description](#description)
- [properties](#properties)
Expand All @@ -1126,6 +1140,7 @@ Permitted children:
- [include](#include)
- [exclude](#exclude)
- [autoLayout](#autoLayout)
- [default](#default)
- [animation](#animation)
- [title](#title)
- [description](#description)
Expand All @@ -1146,6 +1161,7 @@ Permitted children:
- [include](#include)
- [exclude](#exclude)
- [autoLayout](#autoLayout)
- [default](#default)
- [animation](#animation)
- [title](#title)
- [description](#description)
Expand Down Expand Up @@ -1250,6 +1266,14 @@ The second property is the separation of ranks in pixels (default: `300`), while
Please note that if your DSL workspace does not explicitly define any views, the DSL parser will automatically create a default set of views for you, with auto-layout enabled.
To change this behaviour, you can either (1) explicitly define your views or (2) use a script to disable automatic layout ([example](https://github.com/structurizr/dsl/tree/master/docs/cookbook/scripts#create-the-default-views-without-automatic-layout)).

### default

Sets the default view to be shown.

```
default
```

### animation

The `animation` keyword defines the animation for the specified view.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected String[] getPermittedTokens() {
StructurizrDslTokens.INCLUDE_IN_VIEW_TOKEN,
StructurizrDslTokens.EXCLUDE_IN_VIEW_TOKEN,
StructurizrDslTokens.AUTOLAYOUT_VIEW_TOKEN,
StructurizrDslTokens.DEFAULT_VIEW_TOKEN,
StructurizrDslTokens.ANIMATION_IN_VIEW_TOKEN,
StructurizrDslTokens.VIEW_TITLE_TOKEN,
StructurizrDslTokens.VIEW_DESCRIPTION_TOKEN,
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/structurizr/dsl/DefaultViewParser.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.structurizr.dsl;

import com.structurizr.view.View;

final class DefaultViewParser extends AbstractParser {

void parse(ViewDslContext context) {
View view = context.getView();
context.getWorkspace().getViews().getConfiguration().setDefaultView(view);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected String[] getPermittedTokens() {
StructurizrDslTokens.INCLUDE_IN_VIEW_TOKEN,
StructurizrDslTokens.EXCLUDE_IN_VIEW_TOKEN,
StructurizrDslTokens.AUTOLAYOUT_VIEW_TOKEN,
StructurizrDslTokens.DEFAULT_VIEW_TOKEN,
StructurizrDslTokens.ANIMATION_IN_VIEW_TOKEN,
StructurizrDslTokens.VIEW_TITLE_TOKEN,
StructurizrDslTokens.VIEW_DESCRIPTION_TOKEN,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ DynamicView getView() {
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.AUTOLAYOUT_VIEW_TOKEN,
StructurizrDslTokens.DEFAULT_VIEW_TOKEN,
StructurizrDslTokens.VIEW_TITLE_TOKEN,
StructurizrDslTokens.VIEW_DESCRIPTION_TOKEN,
StructurizrDslTokens.PROPERTIES_TOKEN,
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/com/structurizr/dsl/FilteredViewDslContext.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.structurizr.dsl;

import com.structurizr.view.FilteredView;

class FilteredViewDslContext extends ViewDslContext {

FilteredViewDslContext(FilteredView view) {
super(view);
}

FilteredView getView() {
return (FilteredView)super.getView();
}

@Override
protected String[] getPermittedTokens() {
return new String[] {
StructurizrDslTokens.DEFAULT_VIEW_TOKEN,
StructurizrDslTokens.VIEW_TITLE_TOKEN,
StructurizrDslTokens.VIEW_DESCRIPTION_TOKEN,
StructurizrDslTokens.PROPERTIES_TOKEN
};
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ protected String[] getPermittedTokens() {
StructurizrDslTokens.INCLUDE_IN_VIEW_TOKEN,
StructurizrDslTokens.EXCLUDE_IN_VIEW_TOKEN,
StructurizrDslTokens.AUTOLAYOUT_VIEW_TOKEN,
StructurizrDslTokens.DEFAULT_VIEW_TOKEN,
StructurizrDslTokens.ANIMATION_IN_VIEW_TOKEN,
StructurizrDslTokens.VIEW_TITLE_TOKEN,
StructurizrDslTokens.VIEW_DESCRIPTION_TOKEN,
Expand Down
9 changes: 8 additions & 1 deletion src/main/java/com/structurizr/dsl/StructurizrDslParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,11 @@ void parse(List<String> lines, File dslFile) throws StructurizrDslParserExceptio
startContext(new DeploymentViewDslContext(view));

} else if (FILTERED_VIEW_TOKEN.equalsIgnoreCase(firstToken) && inContext(ViewsDslContext.class)) {
new FilteredViewParser().parse(getContext(), tokens);
FilteredView view = new FilteredViewParser().parse(getContext(), tokens.withoutContextStartToken());

if (shouldStartContext(tokens)) {
startContext(new FilteredViewDslContext(view));
}

} else if (IMAGE_VIEW_TOKEN.equalsIgnoreCase(firstToken) && inContext(ViewsDslContext.class)) {
ImageView view = new ImageViewParser().parse(getContext(), tokens.withoutContextStartToken());
Expand Down Expand Up @@ -647,6 +651,9 @@ void parse(List<String> lines, File dslFile) throws StructurizrDslParserExceptio
} else if (AUTOLAYOUT_VIEW_TOKEN.equalsIgnoreCase(firstToken) && inContext(ViewDslContext.class)) {
new AutoLayoutParser().parse(getContext(ModelViewDslContext.class), tokens);

} else if (DEFAULT_VIEW_TOKEN.equalsIgnoreCase(firstToken) && inContext(ViewDslContext.class)) {
new DefaultViewParser().parse(getContext(ViewDslContext.class));

} else if (VIEW_TITLE_TOKEN.equalsIgnoreCase(firstToken) && inContext(ViewDslContext.class)) {
new ViewParser().parseTitle(getContext(ViewDslContext.class), tokens);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class StructurizrDslTokens {
static final String ANIMATION_IN_VIEW_TOKEN = "animation";
static final String ANIMATION_STEP_IN_VIEW_TOKEN = "animationStep";
static final String AUTOLAYOUT_VIEW_TOKEN = "autolayout";
static final String DEFAULT_VIEW_TOKEN = "default";
static final String VIEW_TITLE_TOKEN = "title";
static final String VIEW_DESCRIPTION_TOKEN = "description";
static final String PLANTUML_TOKEN = "plantuml";
Expand Down
29 changes: 29 additions & 0 deletions src/test/dsl/test.dsl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

systemLandscape "SystemLandscape" "Description" {
Expand All @@ -158,6 +160,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

systemContext softwareSystem "SystemContext" "Description" {
Expand All @@ -170,6 +174,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

container softwareSystem "Containers" "Description" {
Expand All @@ -182,6 +188,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

component webApplication "Components" "Description" {
Expand All @@ -194,6 +202,21 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

filtered "SystemLandscape" include "Element,Relationship" "Filtered1"

filtered "SystemLandscape" include "Element,Relationship" "Filtered2" {
title "Filtered view"
description "Description"

properties {
"Name" "Value"
}

default
}

dynamic webApplication "Dynamic" "Description" {
Expand All @@ -206,6 +229,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

deployment * developmentEnvironment "Deployment-Development" "Description" {
Expand All @@ -218,6 +243,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

deployment * "Live" "Deployment-Live" "Description" {
Expand All @@ -230,6 +257,8 @@ workspace "Name" "Description" {
properties {
"Name" "Value"
}

default
}

styles {
Expand Down
24 changes: 24 additions & 0 deletions src/test/java/com/structurizr/dsl/DefaultViewParserTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.structurizr.dsl;

import com.structurizr.view.SystemLandscapeView;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

class DefaultViewParserTests extends AbstractTests {

private final DefaultViewParser parser = new DefaultViewParser();

@Test
void test_parse_SetsTheDefaultView() {
SystemLandscapeView view = workspace.getViews().createSystemLandscapeView("key", "description");
SystemLandscapeViewDslContext context = new SystemLandscapeViewDslContext(view);
context.setWorkspace(workspace);

assertNull(context.getWorkspace().getViews().getConfiguration().getDefaultView());
parser.parse(context);
assertEquals("key", context.getWorkspace().getViews().getConfiguration().getDefaultView());
}

}

0 comments on commit 06c6b3a

Please sign in to comment.