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.pages.app.editor;
35
36 import info.magnolia.cms.beans.config.ServerConfiguration;
37 import info.magnolia.context.MgnlContext;
38 import info.magnolia.i18nsystem.SimpleTranslator;
39 import info.magnolia.jcr.util.NodeTypes;
40 import info.magnolia.objectfactory.Components;
41 import info.magnolia.repository.RepositoryConstants;
42 import info.magnolia.ui.actionbar.ActionbarView;
43 import info.magnolia.ui.api.app.SubAppContext;
44 import info.magnolia.ui.api.view.View;
45 import info.magnolia.ui.contentapp.detail.DetailLocation;
46 import info.magnolia.ui.vaadin.editor.PageEditorView;
47 import info.magnolia.ui.vaadin.editor.pagebar.PageBarView;
48 import info.magnolia.ui.workbench.StatusBarView;
49
50 import javax.inject.Inject;
51 import javax.jcr.Node;
52 import javax.jcr.RepositoryException;
53
54 import com.vaadin.event.ShortcutAction;
55 import com.vaadin.event.ShortcutListener;
56 import com.vaadin.server.Sizeable.Unit;
57 import com.vaadin.ui.Alignment;
58 import com.vaadin.ui.Component;
59 import com.vaadin.ui.CssLayout;
60 import com.vaadin.ui.HorizontalLayout;
61 import com.vaadin.ui.Label;
62 import com.vaadin.ui.Panel;
63 import com.vaadin.ui.VerticalLayout;
64
65
66
67
68 public class PagesEditorSubAppViewImpl implements PagesEditorSubAppView {
69
70
71 private final Panel wrapper = new Panel();
72
73 private final HorizontalLayout root = new HorizontalLayout();
74
75 private final VerticalLayout container = new VerticalLayout();
76
77 private Listener listener;
78
79 private PageEditorView pageEditor;
80
81 private ActionbarView actionBar;
82
83 private final CssLayout actionBarWrapper = new CssLayout();
84
85 private PageBarView pageBarView;
86
87 private StatusBarView statusBarView;
88
89 private final SubAppContext subAppContext;
90
91 private final SimpleTranslator i18n;
92 private ServerConfiguration serverConfiguration;
93
94 private HorizontalLayout activationStatus;
95
96
97
98
99 @Deprecated
100 public PagesEditorSubAppViewImpl(PageBarView pageBarView) {
101 this(pageBarView, Components.getComponent(SubAppContext.class), Components.getComponent(SimpleTranslator.class), Components.getComponent(ServerConfiguration.class));
102 }
103
104 @Inject
105 public PagesEditorSubAppViewImpl(PageBarView pageBarView, SubAppContext subAppContext, SimpleTranslator i18n, ServerConfiguration serverConfiguration) {
106 this.pageBarView = pageBarView;
107 this.subAppContext = subAppContext;
108 this.i18n = i18n;
109 this.serverConfiguration = serverConfiguration;
110
111 root.setSizeFull();
112 root.setStyleName("pageeditor");
113 root.addComponent(container);
114 root.setExpandRatio(container, 1);
115 root.setSpacing(true);
116 root.setMargin(false);
117
118 container.setSizeFull();
119 container.addStyleName("editor");
120
121 actionBarWrapper.setHeight(100, Unit.PERCENTAGE);
122 actionBarWrapper.addStyleName("actionbar");
123 root.addComponent(actionBarWrapper);
124 root.setExpandRatio(actionBarWrapper, 0);
125
126 wrapper.setSizeFull();
127 wrapper.setContent(root);
128 wrapper.addShortcutListener(new ShortcutListener("", ShortcutAction.KeyCode.ESCAPE, null) {
129 @Override
130 public void handleAction(Object sender, Object target) {
131 listener.onEscape();
132 }
133 });
134 wrapper.focus();
135
136 }
137
138 @Override
139 public void setListener(Listener listener) {
140 this.listener = listener;
141 this.pageBarView.setListener(listener);
142 }
143
144 @Override
145 public void setPageBarView(PageBarView pageBarView) {
146 this.pageBarView = pageBarView;
147 container.addComponentAsFirst(pageBarView.asVaadinComponent());
148 }
149
150 @Override
151 public void setPageEditorView(PageEditorView pageEditor) {
152 this.pageEditor = pageEditor;
153 container.addComponent(pageEditor.asVaadinComponent(), 1);
154 container.setExpandRatio(pageEditor.asVaadinComponent(), 1f);
155 }
156
157 @Override
158 public void setActionbarView(final ActionbarView actionBar) {
159 Component c = actionBar.asVaadinComponent();
160 Component old = actionBarWrapper.getComponentCount() != 0 ? actionBarWrapper.getComponent(0) : null;
161 if (old == null) {
162 actionBarWrapper.addComponent(c);
163 } else {
164 actionBarWrapper.replaceComponent(old, c);
165 }
166 this.actionBar = actionBar;
167 }
168
169 @Override
170 public void setStatusBarView(StatusBarView statusBarView) {
171 this.statusBarView = statusBarView;
172 if (serverConfiguration.isAdmin()) {
173 DetailLocation location = DetailLocation.wrap(this.subAppContext.getLocation());
174 String nodePath = location.getNodePath();
175 HorizontalLayout status = getActivationStatus(nodePath);
176 if (activationStatus != null) {
177 this.statusBarView.removeComponent(activationStatus);
178 }
179 this.statusBarView.addComponent(status, Alignment.MIDDLE_CENTER);
180 this.activationStatus = status;
181 }
182 container.addComponent(this.statusBarView.asVaadinComponent());
183 }
184
185 @Override
186 public Component asVaadinComponent() {
187 return wrapper;
188 }
189
190 @Override
191 public void hideActionbar(boolean hide) {
192 if (actionBar != null) {
193 actionBar.asVaadinComponent().setVisible(!hide);
194 }
195 }
196
197 @Override
198 public void setContentView(View view) {
199
200 }
201
202 private HorizontalLayout getActivationStatus(String nodePath) {
203 Integer status;
204 String icon = "activation-status ";
205 String text = i18n.translate("pages.editPage.statusBar.unpublished");
206 try {
207 Node node = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE).getNode(nodePath);
208 status = NodeTypes.Activatable.getActivationStatus(node);
209 } catch (RepositoryException e) {
210 status = NodeTypes.Activatable.ACTIVATION_STATUS_NOT_ACTIVATED;
211 }
212
213 switch (status) {
214 case NodeTypes.Activatable.ACTIVATION_STATUS_MODIFIED:
215 icon += "color-yellow icon-status-orange";
216 text = i18n.translate("pages.editPage.statusBar.modified");
217 break;
218 case NodeTypes.Activatable.ACTIVATION_STATUS_ACTIVATED:
219 icon += "color-green icon-status-green";
220 text = i18n.translate("pages.editPage.statusBar.published");
221 break;
222 default:
223 icon += "color-red icon-status-red";
224 }
225
226 Label iconLabel = new Label();
227 iconLabel.addStyleName(icon);
228
229 Label textLabel = new Label();
230 textLabel.addStyleName("activationstatus");
231 textLabel.setValue(text);
232
233 HorizontalLayout layout = new HorizontalLayout();
234 layout.addStyleName("statusbar");
235 layout.addComponent(iconLabel);
236 layout.addComponent(textLabel);
237
238 return layout;
239 }
240
241 }