Skip to content

Package: DefaultTreeMasterDetailCache

DefaultTreeMasterDetailCache

nameinstructionbranchcomplexitylinemethod
DefaultTreeMasterDetailCache()
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
DefaultTreeMasterDetailCache(int)
M: 15 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
cache(ECPSWTView)
M: 10 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
clear()
M: 14 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
getCachedView(EObject)
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
isChached(EObject)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2011-2019 EclipseSource Muenchen GmbH and others.
3: *
4: * All rights reserved. This program and the accompanying materials
5: * are made available under the terms of the Eclipse Public License 2.0
6: * which accompanies this distribution, and is available at
7: * https://www.eclipse.org/legal/epl-2.0/
8: *
9: * SPDX-License-Identifier: EPL-2.0
10: *
11: * Contributors:
12: * Eugen Neufeld - initial API and implementation
13: * Christian W. Damus - bugs 527686, 549565
14: ******************************************************************************/
15: package org.eclipse.emfforms.spi.swt.treemasterdetail;
16:
17: import java.util.ArrayList;
18: import java.util.LinkedHashMap;
19: import java.util.List;
20: import java.util.Map;
21:
22: import org.eclipse.emf.ecore.EClass;
23: import org.eclipse.emf.ecore.EObject;
24: import org.eclipse.emf.ecp.ui.view.swt.ECPSWTView;
25: import org.eclipse.emf.ecp.view.spi.swt.masterdetail.BasicDetailViewCache;
26:
27: /**
28: * A default implementation of the TreeMasterDetailCache which uses the EClass as the key.
29: *
30: * @author Eugen Neufeld
31: * @since 1.9
32: * @deprecated Since 1.22, use the {@link BasicDetailViewCache} API, instead.
33: */
34: @Deprecated
35: public class DefaultTreeMasterDetailCache implements TreeMasterDetailCache {
36:
37:         private final Map<EClass, ECPSWTView> cache;
38:
39:         /**
40:          * Creates a cache with maximal 5 entries.
41:          */
42:         public DefaultTreeMasterDetailCache() {
43:                 this(5);
44:         }
45:
46:         /**
47:          * Creates a cache with a custom number of maximal entries.
48:          *
49:          * @param maxEntries The number of maximal entries to cache
50:          */
51:         public DefaultTreeMasterDetailCache(final int maxEntries) {
52:                 cache = new LinkedHashMap<EClass, ECPSWTView>(maxEntries + 1, .75F, true) {
53:                         private static final long serialVersionUID = 1L;
54:
55:                         // This method is called just after a new entry has been added
56:                         @Override
57:                         public boolean removeEldestEntry(Map.Entry<EClass, ECPSWTView> eldest) {
58:                                 final boolean result = size() > maxEntries;
59:                                 if (result) {
60:                                         eldest.getValue().dispose();
61:                                 }
62:                                 return result;
63:                         }
64:                 };
65:         }
66:
67:         @Override
68:         public boolean isChached(EObject selection) {
69:                 return cache.containsKey(selection.eClass());
70:         }
71:
72:         @Override
73:         public ECPSWTView getCachedView(EObject selection) {
74:                 return cache.get(selection.eClass());
75:         }
76:
77:         @Override
78:         public void cache(ECPSWTView ecpView) {
79:                 cache.put(ecpView.getViewModelContext().getDomainModel().eClass(), ecpView);
80:         }
81:
82:         @Override
83:         public void clear() {
84:                 final List<ECPSWTView> records = new ArrayList<>(cache.values());
85:                 cache.clear();
86:                 records.forEach(ECPSWTView::dispose);
87:         }
88:
89: }