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.module.googlesitemap.app.subapp.sitemapdetail; |
35 |
|
|
36 |
|
import info.magnolia.context.MgnlContext; |
37 |
|
import info.magnolia.event.EventBus; |
38 |
|
import info.magnolia.jcr.util.PropertyUtil; |
39 |
|
import info.magnolia.module.googlesitemap.GoogleSiteMapConfiguration; |
40 |
|
import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.base.SiteMapContentView; |
41 |
|
import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.base.SiteMapDetailPresenter; |
42 |
|
import info.magnolia.module.googlesitemap.app.subapp.sitemapdetail.event.EntrySelectedEvent; |
43 |
|
import info.magnolia.module.googlesitemap.bean.SiteMapEntry; |
44 |
|
import info.magnolia.objectfactory.ComponentProvider; |
45 |
|
import info.magnolia.ui.actionbar.ActionbarPresenter; |
46 |
|
import info.magnolia.ui.api.action.ActionDefinition; |
47 |
|
import info.magnolia.ui.api.action.ActionExecutionException; |
48 |
|
import info.magnolia.ui.api.app.SubAppContext; |
49 |
|
import info.magnolia.ui.api.app.SubAppEventBus; |
50 |
|
import info.magnolia.ui.api.event.AdmincentralEventBus; |
51 |
|
import info.magnolia.ui.api.event.ContentChangedEvent; |
52 |
|
import info.magnolia.ui.contentapp.detail.DetailLocation; |
53 |
|
import info.magnolia.ui.framework.app.SubAppActionExecutor; |
54 |
|
import info.magnolia.ui.vaadin.actionbar.ActionbarView; |
55 |
|
import info.magnolia.ui.vaadin.integration.NullItem; |
56 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; |
57 |
|
|
58 |
|
import javax.inject.Inject; |
59 |
|
import javax.inject.Named; |
60 |
|
import javax.jcr.Node; |
61 |
|
import javax.jcr.RepositoryException; |
62 |
|
import javax.jcr.Session; |
63 |
|
|
64 |
|
import org.apache.commons.lang.StringUtils; |
65 |
|
import org.slf4j.Logger; |
66 |
|
import org.slf4j.LoggerFactory; |
67 |
|
|
68 |
|
|
69 |
|
@link |
70 |
|
@link |
71 |
|
|
|
|
| 0% |
Uncovered Elements: 72 (72) |
Complexity: 20 |
Complexity Density: 0.4 |
|
72 |
|
public class SiteMapEditorPresenter implements EntrySelectedEvent.Handler, ActionbarPresenter.Listener { |
73 |
|
|
74 |
|
private Logger log = LoggerFactory.getLogger(getClass()); |
75 |
|
|
76 |
|
public static final String EDIT_ACTIONS_GROUP = "editActions"; |
77 |
|
|
78 |
|
private SiteMapEditorView view; |
79 |
|
|
80 |
|
private SiteMapDetailPresenter contentPresenter; |
81 |
|
|
82 |
|
private ActionbarPresenter actionbarPresenter; |
83 |
|
|
84 |
|
private SubAppContext appContext; |
85 |
|
|
86 |
|
private EventBus eventBus; |
87 |
|
|
88 |
|
private EventBus adminCentralEventBus; |
89 |
|
|
90 |
|
private SubAppActionExecutor executor; |
91 |
|
|
92 |
|
private JcrNodeAdapter nodeAdapter; |
93 |
|
|
94 |
|
private ComponentProvider provider; |
95 |
|
|
96 |
|
private String targetWorkspace; |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 9 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
98 |
0
|
@Inject... |
99 |
|
public SiteMapEditorPresenter( |
100 |
|
SiteMapEditorView view, |
101 |
|
ActionbarPresenter actionbarPresenter, |
102 |
|
SubAppContext appContext, |
103 |
|
@Named(SubAppEventBus.NAME) EventBus eventBus, |
104 |
|
@Named(AdmincentralEventBus.NAME) final EventBus adminCentralEventBus, |
105 |
|
SubAppActionExecutor executor, |
106 |
|
ComponentProvider provider) { |
107 |
0
|
this.view = view; |
108 |
0
|
this.actionbarPresenter = actionbarPresenter; |
109 |
0
|
this.appContext = appContext; |
110 |
0
|
this.eventBus = eventBus; |
111 |
0
|
this.adminCentralEventBus = adminCentralEventBus; |
112 |
0
|
this.executor = executor; |
113 |
0
|
this.provider = provider; |
114 |
0
|
this.eventBus.addHandler(EntrySelectedEvent.class, this); |
115 |
0
|
this.actionbarPresenter.setListener(this); |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 13 (13) |
Complexity: 2 |
Complexity Density: 0.18 |
|
118 |
0
|
public SiteMapEditorView start() {... |
119 |
0
|
SiteMapEditorSubAppDescriptor descriptor = (SiteMapEditorSubAppDescriptor) appContext.getSubAppDescriptor(); |
120 |
0
|
this.targetWorkspace = descriptor.getTargetWorkspace(); |
121 |
0
|
this.contentPresenter = provider.newInstance(descriptor.getPresenterClass()); |
122 |
|
|
123 |
0
|
ActionbarView actionbarView = actionbarPresenter.start(descriptor.getActionbar()); |
124 |
0
|
view.setActionbarView(actionbarView); |
125 |
|
|
126 |
0
|
SiteMapContentView contentView = contentPresenter.start(); |
127 |
0
|
view.setContentView(contentView); |
128 |
|
|
129 |
0
|
if (contentPresenter.getCurrentSelection() == null) { |
130 |
0
|
actionbarPresenter.disableGroup(EDIT_ACTIONS_GROUP); |
131 |
|
} |
132 |
|
|
133 |
0
|
adminCentralEventBus.addHandler(ContentChangedEvent.class, new ContentChangedEvent.Handler() { |
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
134 |
0
|
@Override... |
135 |
|
public void onContentChanged(ContentChangedEvent event) { |
136 |
0
|
if (targetWorkspace.equals(event.getWorkspace())) { |
137 |
0
|
contentPresenter.edit(nodeAdapter.getJcrItem()); |
138 |
|
} |
139 |
|
} |
140 |
|
}); |
141 |
0
|
return view; |
142 |
|
} |
143 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
144 |
0
|
public void setSiteMapNode(JcrNodeAdapter nodeAdapter) {... |
145 |
0
|
this.nodeAdapter = nodeAdapter; |
146 |
0
|
contentPresenter.edit(nodeAdapter.getJcrItem()); |
147 |
|
} |
148 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
149 |
0
|
@Override... |
150 |
|
public void onEntriesSelected(SiteMapEntry entry) { |
151 |
0
|
if (entry == null) { |
152 |
0
|
actionbarPresenter.disableGroup(EDIT_ACTIONS_GROUP); |
153 |
|
} else { |
154 |
0
|
actionbarPresenter.enableGroup(EDIT_ACTIONS_GROUP); |
155 |
|
} |
156 |
|
} |
157 |
|
|
|
|
| 0% |
Uncovered Elements: 10 (10) |
Complexity: 4 |
Complexity Density: 0.5 |
|
158 |
0
|
@Override... |
159 |
|
public void onActionbarItemClicked(String itemName) { |
160 |
0
|
try { |
161 |
0
|
SiteMapEntry entry = contentPresenter.getCurrentSelection(); |
162 |
0
|
if (entry != null) { |
163 |
0
|
Node pageNode = MgnlContext.getJCRSession(targetWorkspace).getNode(entry.getPath()); |
164 |
0
|
executor.execute(itemName, new JcrNodeAdapter(pageNode)); |
165 |
|
} else { |
166 |
0
|
executor.execute(itemName, new NullItem()); |
167 |
|
} |
168 |
|
} catch (ActionExecutionException e) { |
169 |
0
|
e.printStackTrace(); |
170 |
|
} catch (RepositoryException e) { |
171 |
0
|
e.printStackTrace(); |
172 |
|
} |
173 |
|
} |
174 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
175 |
0
|
@Override... |
176 |
|
public String getLabel(String itemName) { |
177 |
0
|
ActionDefinition actionDefinition = executor.getActionDefinition(itemName); |
178 |
0
|
return actionDefinition != null ? actionDefinition.getLabel() : null; |
179 |
|
} |
180 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
181 |
0
|
@Override... |
182 |
|
public String getIcon(String itemName) { |
183 |
0
|
try { |
184 |
0
|
ActionDefinition actionDefinition = executor.getActionDefinition(itemName); |
185 |
0
|
return actionDefinition != null ? actionDefinition.getIcon() : null; |
186 |
|
} catch (Exception e) { |
187 |
0
|
e.printStackTrace(); |
188 |
0
|
return null; |
189 |
|
} |
190 |
|
} |
191 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
192 |
0
|
public String getCaptionForLocation(DetailLocation location) {... |
193 |
0
|
return contentPresenter.getLabel() + ": " + getSiteMapName(location); |
194 |
|
} |
195 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
196 |
0
|
private String getSiteMapName(DetailLocation location) {... |
197 |
0
|
String caption = StringUtils.EMPTY; |
198 |
0
|
try { |
199 |
0
|
Session session = MgnlContext.getJCRSession(GoogleSiteMapConfiguration.WORKSPACE); |
200 |
0
|
Node node = session.getNode(location.getNodePath()); |
201 |
0
|
caption = PropertyUtil.getString(node, GoogleSiteMapConfiguration.SITE_MAP_DISPLAY_NAME_PROPERTY_NAME, node.getName()); |
202 |
|
} catch (RepositoryException e) { |
203 |
0
|
log.warn("Could not set page Tab Title for item : {}", location.getNodePath(), e); |
204 |
|
} |
205 |
0
|
return caption; |
206 |
|
} |
207 |
|
} |