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.event.EventBus;
37 import info.magnolia.module.ModuleRegistry;
38 import info.magnolia.objectfactory.ComponentProvider;
39 import info.magnolia.resourceloader.ResourceOrigin;
40 import info.magnolia.resources.app.ResourcesContentConnector;
41 import info.magnolia.resources.app.workbench.ResourcesContainer;
42 import info.magnolia.resources.app.workbench.tools.FilterClasspathResourcesEvent;
43 import info.magnolia.ui.vaadin.integration.contentconnector.ContentConnector;
44 import info.magnolia.ui.workbench.tree.TreePresenter;
45 import info.magnolia.ui.workbench.tree.TreeView;
46
47 import java.util.List;
48
49 import javax.inject.Inject;
50
51 import com.google.common.collect.Lists;
52 import com.vaadin.data.Container;
53 import com.vaadin.data.Item;
54 import com.vaadin.data.Property;
55
56
57
58
59 public class ResourcesTreePresenter extends TreePresenter {
60
61 private static final String ICON_DIRECTORY = "icon-folder-l";
62 private static final String ICON_FILE = "icon-file-text";
63
64 private final ModuleRegistry moduleRegistry;
65
66 @Inject
67 public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ModuleRegistry moduleRegistry) {
68 super(view, componentProvider);
69 this.moduleRegistry = moduleRegistry;
70 }
71
72
73
74
75 @Deprecated
76 public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ContentConnector contentConnector, ModuleRegistry moduleRegistry, EventBus eventBus) {
77 this(view, componentProvider, moduleRegistry);
78 }
79
80 @Override
81 protected Container.Hierarchical createContainer() {
82 final ResourceOrigin<?> origin = resourcesContentConnector().getOrigin();
83 final List<String> moduleNames = Lists.newArrayList(moduleRegistry.getModuleNames());
84 final ResourcesContainer resourcesContainer = new ResourcesContainer(origin, moduleNames);
85 eventBus.addHandler(FilterClasspathResourcesEvent.class, new FilterClasspathResourcesEvent.Handler() {
86 @Override
87 public void onResourceFilterChange(FilterClasspathResourcesEvent event) {
88 resourcesContainer.setClasspathResourcesFiltered(event.isFilteringClasspathResources());
89 }
90 });
91 return resourcesContainer;
92 }
93
94 protected ResourcesContentConnector resourcesContentConnector() {
95 return (ResourcesContentConnector)contentConnector;
96 }
97
98 @Override
99 public String getIcon(Item item) {
100 Property<Boolean> isDirectory = item.getItemProperty(ResourcesContainer.DIRECTORY_PROPERTY_ID);
101 if (isDirectory != null) {
102 return isDirectory.getValue() ? ICON_DIRECTORY : ICON_FILE;
103 }
104 return null;
105 }
106
107 }