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.workbench.tree; |
35 |
|
|
36 |
|
import info.magnolia.context.Context; |
37 |
|
import info.magnolia.event.EventBus; |
38 |
|
import info.magnolia.jcr.util.NodeTypes; |
39 |
|
import info.magnolia.jcr.util.NodeUtil; |
40 |
|
import info.magnolia.module.ModuleRegistry; |
41 |
|
import info.magnolia.objectfactory.ComponentProvider; |
42 |
|
import info.magnolia.resourceloader.ResourceOrigin; |
43 |
|
import info.magnolia.resources.app.ResourcesContentConnector; |
44 |
|
import info.magnolia.resources.app.availability.IsResourcePresentInJcrRule; |
45 |
|
import info.magnolia.resources.app.utils.ResourceUtils; |
46 |
|
import info.magnolia.resources.app.workbench.ResourcesContainer; |
47 |
|
import info.magnolia.resources.app.workbench.tools.FilterClasspathResourcesEvent; |
48 |
|
import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector; |
49 |
|
import info.magnolia.ui.vaadin.integration.jcr.JcrNodeAdapter; |
50 |
|
import info.magnolia.ui.workbench.tree.TreePresenter; |
51 |
|
import info.magnolia.ui.workbench.tree.TreeView; |
52 |
|
|
53 |
|
import java.util.List; |
54 |
|
|
55 |
|
import javax.inject.Inject; |
56 |
|
import javax.jcr.Node; |
57 |
|
import javax.jcr.RepositoryException; |
58 |
|
|
59 |
|
import com.google.common.base.Optional; |
60 |
|
import com.google.common.collect.Lists; |
61 |
|
import com.vaadin.data.Container; |
62 |
|
import com.vaadin.data.Item; |
63 |
|
import com.vaadin.data.Property; |
64 |
|
|
65 |
|
|
66 |
|
@link |
67 |
|
|
|
|
| 0% |
Uncovered Elements: 42 (42) |
Complexity: 13 |
Complexity Density: 0.48 |
|
68 |
|
public class ResourcesTreePresenter extends TreePresenter { |
69 |
|
|
70 |
|
private static final String ICON_DIRECTORY = "icon-folder-l"; |
71 |
|
private static final String ICON_FILE = "icon-file-text"; |
72 |
|
|
73 |
|
private final ModuleRegistry moduleRegistry; |
74 |
|
private final Optional<Context> context; |
75 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
76 |
0 |
@Inject... |
77 |
|
public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ModuleRegistry moduleRegistry, Context context) { |
78 |
0 |
super(view, componentProvider); |
79 |
0 |
this.moduleRegistry = moduleRegistry; |
80 |
0 |
this.context = Optional.fromNullable(context); |
81 |
|
} |
82 |
|
|
83 |
|
|
84 |
|
@deprecated@link |
85 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
0 |
public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ModuleRegistry moduleRegistry) {... |
87 |
0 |
this(view, componentProvider, moduleRegistry, null); |
88 |
|
} |
89 |
|
|
90 |
|
|
91 |
|
@deprecated@link |
92 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
93 |
0 |
@Deprecated... |
94 |
|
public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ContentConnector contentConnector, ModuleRegistry moduleRegistry, EventBus eventBus) { |
95 |
0 |
this(view, componentProvider, moduleRegistry, null); |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
|
98 |
0 |
@Override... |
99 |
|
protected Container.Hierarchical createContainer() { |
100 |
0 |
final ResourceOrigin<?> origin = resourcesContentConnector().getOrigin(); |
101 |
0 |
final List<String> moduleNames = Lists.newArrayList(moduleRegistry.getModuleNames()); |
102 |
0 |
final ResourcesContainer resourcesContainer = new ResourcesContainer(origin, moduleNames); |
103 |
|
|
104 |
0 |
eventBus.addHandler(FilterClasspathResourcesEvent.class, new FilterClasspathResourcesEvent.Handler() { |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
105 |
0 |
@Override... |
106 |
|
public void onResourceFilterChange(FilterClasspathResourcesEvent event) { |
107 |
0 |
resourcesContainer.setClasspathResourcesFiltered(event.isFilteringClasspathResources()); |
108 |
|
} |
109 |
|
}); |
110 |
|
|
111 |
0 |
return resourcesContainer; |
112 |
|
} |
113 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
114 |
0 |
protected ResourcesContentConnector resourcesContentConnector() {... |
115 |
0 |
return (ResourcesContentConnector)contentConnector; |
116 |
|
} |
117 |
|
|
|
|
| 0% |
Uncovered Elements: 23 (23) |
Complexity: 7 |
Complexity Density: 0.47 |
|
118 |
0 |
@Override... |
119 |
|
public String getIcon(Item item) { |
120 |
0 |
String resourcePath = item.getItemProperty(ResourcesContainer.RESOURCE_PATH).getValue().toString(); |
121 |
0 |
boolean isResourcePresentInJcr = new IsResourcePresentInJcrRule(resourcesContentConnector().getOrigin()).isAvailable(Lists.newArrayList(resourcePath)); |
122 |
|
|
123 |
0 |
if (context.isPresent() && isResourcePresentInJcr) { |
124 |
0 |
JcrNodeAdapter jcrNodeAdapter = ResourceUtils.getJcrNodeAdapterFor(context.get(), item); |
125 |
0 |
Node node = jcrNodeAdapter.getJcrItem(); |
126 |
|
|
127 |
0 |
boolean isDeleted; |
128 |
0 |
try { |
129 |
0 |
isDeleted = NodeUtil.hasMixin(node, NodeTypes.Deleted.NAME); |
130 |
|
} catch (RepositoryException ignored) { |
131 |
0 |
isDeleted = false; |
132 |
|
} |
133 |
0 |
if (isDeleted) { |
134 |
0 |
return ICON_TRASH; |
135 |
|
} |
136 |
|
} |
137 |
|
|
138 |
0 |
Property<Boolean> isDirectory = item.getItemProperty(ResourcesContainer.DIRECTORY_PROPERTY_ID); |
139 |
0 |
if (isDirectory != null) { |
140 |
0 |
return isDirectory.getValue() ? ICON_DIRECTORY : ICON_FILE; |
141 |
|
} |
142 |
0 |
return null; |
143 |
|
} |
144 |
|
|
145 |
|
} |