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.resources.app.action; |
35 |
|
|
36 |
|
import info.magnolia.event.EventBus; |
37 |
|
import info.magnolia.i18nsystem.SimpleTranslator; |
38 |
|
import info.magnolia.resourceloader.Resource; |
39 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
40 |
|
import info.magnolia.resources.app.ResourcesContentConnector; |
41 |
|
import info.magnolia.ui.api.action.ActionExecutionException; |
42 |
|
import info.magnolia.ui.api.app.AppContext; |
43 |
|
import info.magnolia.ui.api.context.UiContext; |
44 |
|
import info.magnolia.ui.api.event.AdmincentralEventBus; |
45 |
|
import info.magnolia.ui.api.location.LocationController; |
46 |
|
import info.magnolia.ui.dialog.formdialog.FormDialogPresenter; |
47 |
|
import info.magnolia.ui.dialog.formdialog.FormDialogPresenterFactory; |
48 |
|
import info.magnolia.ui.form.EditorCallback; |
49 |
|
import info.magnolia.ui.framework.action.OpenCreateDialogActionDefinition; |
50 |
|
import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector; |
51 |
|
import info.magnolia.ui.vaadin.overlay.MessageStyleTypeEnum; |
52 |
|
|
53 |
|
import javax.inject.Named; |
54 |
|
|
55 |
|
import org.apache.commons.lang3.StringUtils; |
56 |
|
|
57 |
|
import com.vaadin.data.Item; |
58 |
|
import com.vaadin.data.util.PropertysetItem; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
|
64 |
|
@link@link |
65 |
|
@link |
66 |
|
|
67 |
|
@see |
68 |
|
@param@link |
69 |
|
|
|
|
| 78.4% |
Uncovered Elements: 8 (37) |
Complexity: 9 |
Complexity Density: 0.36 |
|
70 |
|
public abstract class AbstractAddResourceAction<D extends OpenCreateDialogActionDefinition> extends AbstractResourceAction<D> { |
71 |
|
|
72 |
|
private PropertysetItem newResourceItem; |
73 |
|
|
74 |
|
private final Item resourceItem; |
75 |
|
private final FormDialogPresenterFactory formDialogPresenterFactory; |
76 |
|
|
77 |
|
protected final AppContext appContext; |
78 |
|
protected final UiContext uiContext; |
79 |
|
protected final SimpleTranslator i18n; |
80 |
|
protected final ResourcesContentConnector contentConnector; |
81 |
|
protected final LocationController locationController; |
82 |
|
protected final EventBus eventBus; |
83 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
|
84 |
5 |
public AbstractAddResourceAction(D definition, Item resourceItem, FormDialogPresenterFactory formDialogPresenterFactory, AppContext appContext, UiContext uiContext, ContentConnector contentConnector, SimpleTranslator i18n, LocationController locationController, ResourceOrigin origin, @Named(AdmincentralEventBus.NAME) EventBus eventBus) {... |
85 |
5 |
super(definition, origin); |
86 |
5 |
this.resourceItem = resourceItem; |
87 |
5 |
this.formDialogPresenterFactory = formDialogPresenterFactory; |
88 |
5 |
this.appContext = appContext; |
89 |
5 |
this.uiContext = uiContext; |
90 |
5 |
this.contentConnector = (ResourcesContentConnector) contentConnector; |
91 |
5 |
this.locationController = locationController; |
92 |
5 |
this.i18n = i18n; |
93 |
5 |
this.eventBus = eventBus; |
94 |
|
} |
95 |
|
|
|
|
| 53.8% |
Uncovered Elements: 6 (13) |
Complexity: 3 |
Complexity Density: 0.33 |
|
96 |
5 |
@Override... |
97 |
|
public void execute() throws ActionExecutionException { |
98 |
5 |
final String dialogName = getDefinition().getDialogName(); |
99 |
5 |
if (StringUtils.isBlank(dialogName)) { |
100 |
0 |
uiContext.openNotification(MessageStyleTypeEnum.ERROR, false, i18n.translate("ui-framework.actions.no.dialog.definition", getDefinition().getName())); |
101 |
0 |
return; |
102 |
|
} |
103 |
|
|
104 |
5 |
final FormDialogPresenter formDialogPresenter = formDialogPresenterFactory.createFormDialogPresenter(dialogName); |
105 |
5 |
if (formDialogPresenter == null) { |
106 |
0 |
uiContext.openNotification(MessageStyleTypeEnum.ERROR, false, i18n.translate("ui-framework.actions.dialog.not.registered", dialogName)); |
107 |
0 |
return; |
108 |
|
} |
109 |
|
|
110 |
5 |
formDialogPresenter.start(getNewResourceItem(), getDefinition().getDialogName(), uiContext, new EditorCallback() { |
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
111 |
5 |
@Override... |
112 |
|
public void onSuccess(String actionName) { |
113 |
5 |
addResource(); |
114 |
5 |
formDialogPresenter.closeDialog(); |
115 |
|
} |
116 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
117 |
0 |
@Override... |
118 |
|
public void onCancel() { |
119 |
0 |
formDialogPresenter.closeDialog(); |
120 |
|
} |
121 |
|
}); |
122 |
|
} |
123 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
5 |
protected Resource getParentResource() {... |
125 |
5 |
return unwrapResource(resourceItem); |
126 |
|
} |
127 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
128 |
10 |
protected PropertysetItem getNewResourceItem() {... |
129 |
10 |
if (newResourceItem == null) { |
130 |
5 |
newResourceItem = new PropertysetItem(); |
131 |
|
} |
132 |
10 |
return newResourceItem; |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
|
@link |
137 |
|
@link |
138 |
|
|
139 |
|
protected abstract void addResource(); |
140 |
|
|
141 |
|
} |