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.resourceloader.Resource;
37 import info.magnolia.resourceloader.ResourceOrigin;
38 import info.magnolia.resources.app.workbench.ResourcesContainer;
39 import info.magnolia.ui.api.action.AbstractAction;
40 import info.magnolia.ui.api.action.ActionDefinition;
41
42 import com.google.common.base.Joiner;
43 import com.vaadin.data.Item;
44 import com.vaadin.data.Property;
45
46
47
48
49
50 public abstract class AbstractResourceAction<D extends ActionDefinition> extends AbstractAction<D> {
51
52 private ResourceOrigin<?> origin;
53
54 protected static final String HOTFIX_SUBAPP_NAME = "hotfix";
55 protected static final String DETAIL_SUBAPP_NAME = "detail";
56
57 protected AbstractResourceAction(D definition, ResourceOrigin<?> origin) {
58 super(definition);
59 this.origin = origin;
60 }
61
62 protected Resource unwrapResource(Item resourceItem) throws IllegalStateException {
63 final Property<String> pathProperty = resourceItem.getItemProperty(ResourcesContainer.RESOURCE_PATH);
64 if (pathProperty == null) {
65 throw new IllegalStateException(String.format("Required [%s] property is missing, available properties are: [%s]", ResourcesContainer.RESOURCE_PATH, Joiner.on(',').join(resourceItem.getItemPropertyIds())));
66 }
67
68 return origin.getByPath(pathProperty.getValue());
69 }
70 }