1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.ui.contentapp.browser;
35
36 import info.magnolia.ui.contentapp.configuration.ContentViewDefinition;
37 import info.magnolia.ui.contentapp.configuration.ContentViewsDefinition;
38 import info.magnolia.ui.contentapp.configuration.WorkbenchDefinition;
39 import info.magnolia.ui.framework.ContextProperty;
40 import info.magnolia.ui.UIComponent;
41 import info.magnolia.ui.framework.UiComponentContext;
42
43 import java.util.function.Consumer;
44
45 import javax.inject.Inject;
46
47 import com.vaadin.ui.HorizontalLayout;
48 import com.vaadin.ui.VerticalLayout;
49
50
51
52
53
54 public class Workbench<T> extends VerticalLayout implements UIComponent {
55
56 private final WorkbenchContext workbenchContext;
57 private final ContentViews<T> contentViews;
58
59 @Inject
60 public Workbench(WorkbenchDefinition<T> definition, WorkbenchContext workbenchContext) {
61 this.workbenchContext = workbenchContext;
62
63 final String defaultDisplayedContentView = definition.getContentViews()
64 .stream()
65 .map(ContentViewDefinition::getName)
66 .findFirst()
67 .orElseThrow(() -> new RuntimeException("No content views defined."));
68
69 this.workbenchContext
70 .displayedContentViewId()
71 .set(defaultDisplayedContentView);
72
73 this.contentViews = getContentViews(definition);
74
75 HorizontalLayout contentViewLayout = new HorizontalLayout();
76 contentViewLayout.setSizeFull();
77 contentViewLayout.addComponent(contentViews);
78 contentViewLayout.setExpandRatio(contentViews, 0f);
79
80 setSizeFull();
81 addStyleName("workbench");
82 setMargin(false);
83 addComponent(contentViews);
84 }
85
86 protected ContentViews<T> getContentViews(WorkbenchDefinition<T> definition) {
87 return create(ContentViewsDefinition.of(definition.getContentViews()), definition.getExtensionViews());
88 }
89
90 public void setTitle(String title) {
91 this.contentViews.setTitle(title);
92 }
93
94 public void setTitle(String title, boolean isHtml) {
95 this.contentViews.setTitle(title, isHtml);
96 }
97
98 public void onContentViewTypeChange(Consumer<String> handler) {
99 workbenchContext
100 .displayedContentViewId()
101 .observeNullable(handler::accept);
102 }
103
104
105
106
107 public interface WorkbenchContext extends UiComponentContext {
108 ContextProperty<String> displayedContentViewId();
109 }
110 }