Clover icon

Magnolia Resources App Module 2.5.3

  1. Project Clover database Thu May 11 2017 16:02:29 CEST
  2. Package info.magnolia.resources.app.workbench.tree

File ResourcesTreePresenter.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart0.png
74% of files have more coverage

Code metrics

8
27
7
1
145
84
13
0.48
3.86
7
1.86

Classes

Class Line # Actions
ResourcesTreePresenter 68 27 0% 13 42
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2015-2017 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
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    * Specialized {@link TreePresenter} which creates an origin-based Vaadin container.
67    */
 
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   
 
76  0 toggle @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 since 2.4.2 - use {@link #ResourcesTreePresenter(TreeView, ComponentProvider, ModuleRegistry, Context)} instead.
85    */
 
86  0 toggle public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ModuleRegistry moduleRegistry) {
87  0 this(view, componentProvider, moduleRegistry, null);
88    }
89   
90    /**
91    * @deprecated since 2.4.1 - use {@link #ResourcesTreePresenter(TreeView, ComponentProvider, ModuleRegistry)} instead.
92    */
 
93  0 toggle @Deprecated
94    public ResourcesTreePresenter(final TreeView view, ComponentProvider componentProvider, ContentConnector contentConnector, ModuleRegistry moduleRegistry, EventBus eventBus) {
95  0 this(view, componentProvider, moduleRegistry, null);
96    }
97   
 
98  0 toggle @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() {
 
105  0 toggle @Override
106    public void onResourceFilterChange(FilterClasspathResourcesEvent event) {
107  0 resourcesContainer.setClasspathResourcesFiltered(event.isFilteringClasspathResources());
108    }
109    });
110   
111  0 return resourcesContainer;
112    }
113   
 
114  0 toggle protected ResourcesContentConnector resourcesContentConnector() {
115  0 return (ResourcesContentConnector)contentConnector;
116    }
117   
 
118  0 toggle @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    }