EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcmbench.navigator]

COVERAGE SUMMARY FOR SOURCE FILE [PCMNavigatorContentProvider.java]

nameclass, %method, %block, %line, %
PCMNavigatorContentProvider.java0%   (0/6)0%   (0/33)0%   (0/574)0%   (0/146)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class MySaveable0%   (0/1)0%   (0/9)0%   (0/57)0%   (0/19)
MySaveable (Resource): void 0%   (0/1)0%   (0/9)0%   (0/4)
doSave (IProgressMonitor): void 0%   (0/1)0%   (0/12)0%   (0/4)
equals (Object): boolean 0%   (0/1)0%   (0/15)0%   (0/5)
getImageDescriptor (): ImageDescriptor 0%   (0/1)0%   (0/2)0%   (0/1)
getName (): String 0%   (0/1)0%   (0/4)0%   (0/1)
getResource (): Resource 0%   (0/1)0%   (0/3)0%   (0/1)
getToolTipText (): String 0%   (0/1)0%   (0/4)0%   (0/1)
hashCode (): int 0%   (0/1)0%   (0/4)0%   (0/1)
isDirty (): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
     
class MySaveablesProvider0%   (0/1)0%   (0/6)0%   (0/129)0%   (0/31)
MySaveablesProvider (ResourceSet): void 0%   (0/1)0%   (0/32)0%   (0/10)
access$0 (MySaveablesProvider, Saveable []): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$1 (MySaveablesProvider, Saveable []): void 0%   (0/1)0%   (0/4)0%   (0/1)
getElements (Saveable): Object [] 0%   (0/1)0%   (0/41)0%   (0/10)
getSaveable (Object): Saveable 0%   (0/1)0%   (0/18)0%   (0/6)
getSaveables (): Saveable [] 0%   (0/1)0%   (0/30)0%   (0/4)
     
class MySaveablesProvider$10%   (0/1)0%   (0/2)0%   (0/32)0%   (0/8)
MySaveablesProvider$1 (MySaveablesProvider): void 0%   (0/1)0%   (0/6)0%   (0/2)
notifyChanged (Notification): void 0%   (0/1)0%   (0/26)0%   (0/6)
     
class MySaveablesProvider$20%   (0/1)0%   (0/4)0%   (0/49)0%   (0/15)
MySaveablesProvider$2 (MySaveablesProvider): void 0%   (0/1)0%   (0/6)0%   (0/2)
notifyChanged (Notification): void 0%   (0/1)0%   (0/35)0%   (0/9)
setTarget (ResourceSet): void 0%   (0/1)0%   (0/4)0%   (0/2)
unsetTarget (ResourceSet): void 0%   (0/1)0%   (0/4)0%   (0/2)
     
class PCMNavigatorContentProvider0%   (0/1)0%   (0/10)0%   (0/257)0%   (0/63)
PCMNavigatorContentProvider (): void 0%   (0/1)0%   (0/75)0%   (0/19)
access$0 (PCMNavigatorContentProvider): StructuredViewer 0%   (0/1)0%   (0/3)0%   (0/1)
dispose (): void 0%   (0/1)0%   (0/1)0%   (0/1)
getAdapter (Class): Object 0%   (0/1)0%   (0/2)0%   (0/1)
getChildren (Object): Object [] 0%   (0/1)0%   (0/79)0%   (0/20)
getElements (Object): Object [] 0%   (0/1)0%   (0/4)0%   (0/1)
getParent (Object): Object 0%   (0/1)0%   (0/31)0%   (0/8)
hasChildren (Object): boolean 0%   (0/1)0%   (0/15)0%   (0/3)
inputChanged (Viewer, Object, Object): void 0%   (0/1)0%   (0/16)0%   (0/5)
populateHashtable (): void 0%   (0/1)0%   (0/31)0%   (0/4)
     
class PCMNavigatorContentProvider$10%   (0/1)0%   (0/2)0%   (0/50)0%   (0/16)
PCMNavigatorContentProvider$1 (PCMNavigatorContentProvider): void 0%   (0/1)0%   (0/6)0%   (0/2)
notifyChanged (Notification): void 0%   (0/1)0%   (0/44)0%   (0/14)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.pcmbench.navigator;
5 
6import java.io.IOException;
7import java.util.ArrayList;
8import java.util.Collection;
9import java.util.HashMap;
10import java.util.Hashtable;
11import java.util.Iterator;
12import java.util.List;
13 
14import org.eclipse.core.resources.IProject;
15import org.eclipse.core.resources.ResourcesPlugin;
16import org.eclipse.core.runtime.CoreException;
17import org.eclipse.core.runtime.IAdaptable;
18import org.eclipse.core.runtime.IProgressMonitor;
19import org.eclipse.emf.common.notify.AdapterFactory;
20import org.eclipse.emf.common.notify.Notification;
21import org.eclipse.emf.common.util.EList;
22import org.eclipse.emf.ecore.EObject;
23import org.eclipse.emf.ecore.resource.Resource;
24import org.eclipse.emf.ecore.resource.ResourceSet;
25import org.eclipse.emf.ecore.util.EContentAdapter;
26import org.eclipse.emf.ecore.util.EcoreUtil;
27import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
28import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
29import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
30import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
31import org.eclipse.emf.transaction.TransactionalEditingDomain;
32import org.eclipse.jface.resource.ImageDescriptor;
33import org.eclipse.jface.viewers.ITreeContentProvider;
34import org.eclipse.jface.viewers.StructuredViewer;
35import org.eclipse.jface.viewers.Viewer;
36import org.eclipse.ui.Saveable;
37import org.eclipse.ui.navigator.SaveablesProvider;
38 
39import de.uka.ipd.sdq.pcm.repository.RepositoryPackage;
40import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory;
41import de.uka.ipd.sdq.pcm.seff.provider.SeffItemProviderAdapterFactory;
42import de.uka.ipd.sdq.pcmbench.ui.provider.categoryaware.CategoryAwareItemProviderAdapterFactory;
43import de.uka.ipd.sdq.pcmbench.ui.provider.categoryaware.GenericCategoryItemProvider;
44import de.uka.ipd.sdq.pcmbench.ui.provider.categoryaware.PalladioCategoryDescriptions;
45 
46 
47class MySaveable extends Saveable
48{
49 
50        private Resource myResource;
51        
52        public MySaveable(Resource r) {
53                myResource = r;
54                r.setTrackingModification(true);
55        }
56 
57        @Override
58        public void doSave(IProgressMonitor monitor) throws CoreException {
59                try {
60                        myResource.save(null);
61                } catch (IOException e) {
62                        throw new CoreException(null);
63                }
64        }
65 
66        public Resource getResource()
67        {
68                return myResource;
69        }
70        
71        @Override
72        public boolean equals(Object object) {
73                if (object instanceof MySaveable)
74                {
75                        MySaveable other = (MySaveable) object;
76                        if (other.getResource() == myResource)
77                                return true;
78                }
79                return false;
80        }
81 
82        @Override
83        public ImageDescriptor getImageDescriptor() {
84                return null;
85        }
86 
87        @Override
88        public String getName() {
89                return myResource.toString();
90        }
91 
92        @Override
93        public String getToolTipText() {
94                return myResource.toString();
95        }
96 
97        @Override
98        public int hashCode() {
99                return myResource.hashCode();
100        }
101 
102        @Override
103        public boolean isDirty() {
104                return myResource.isModified();
105        }
106}
107 
108class MySaveablesProvider extends SaveablesProvider {
109        
110        private ResourceSet rs = null;
111        
112        public MySaveablesProvider(ResourceSet resourceSet) {
113                rs = resourceSet;
114                EContentAdapter dirtyListeners = new EContentAdapter() {
115                        public void notifyChanged(Notification notification) {
116                                if (notification.getNotifier() instanceof EObject)
117                                {
118                                        EObject eObject = (EObject)notification.getNotifier();
119                                        Resource r = eObject.eResource();
120                                        MySaveable s = new MySaveable(r);
121                                        MySaveablesProvider.this.fireSaveablesDirtyChanged(new Saveable[]{s});
122                                }
123                        }
124                };
125                resourceSet.eAdapters().add(dirtyListeners);        
126                
127                EContentAdapter repositoryResourceListeners = new EContentAdapter() {
128                        public void notifyChanged(Notification notification) {
129                                if (notification.getNotifier() instanceof ResourceSet) {
130                                        switch (notification.getFeatureID(ResourceSet.class)) {
131                                        case ResourceSet.RESOURCE_SET__RESOURCES:
132                                                if (notification.getEventType() == Notification.ADD) {
133                                                        Resource r = (Resource)notification.getNewValue();
134                                                        MySaveable s = new MySaveable(r);
135                                                        MySaveablesProvider.this.fireSaveablesOpened(new Saveable[]{s});
136                                                }
137                                                break;
138                                        }
139                                } else {
140                                        super.notifyChanged(notification);
141                                }
142                        }
143 
144                        protected void setTarget(ResourceSet target) {
145                                basicSetTarget(target);
146                        }
147 
148                        protected void unsetTarget(ResourceSet target) {
149                                basicUnsetTarget(target);
150                        }
151                };
152                repositoryResourceListeners.setTarget(resourceSet);
153                resourceSet.eAdapters().add(
154                                repositoryResourceListeners);
155        }
156 
157        @Override
158        public Object[] getElements(Saveable saveable) {
159                MySaveable s = (MySaveable)saveable;
160                if (!s.getResource().isLoaded()) {
161                        try {
162                                s.getResource().load(null);
163                        } catch (IOException e) {
164                                // TODO Auto-generated catch block
165                                e.printStackTrace();
166                        }
167                }
168                EList objects = s.getResource().getContents();
169                ArrayList result = new ArrayList();
170                for (EObject o : (List<EObject>)objects)
171                {
172                        result.add(o);
173                }
174                return result.toArray();
175        }
176 
177        @Override
178        public Saveable getSaveable(Object element) {
179                if (element instanceof EObject)
180                {
181                        EObject eElement = (EObject)element;
182                        Resource r = eElement.eResource();
183                        Saveable saveable = new MySaveable(r);
184                        return saveable;
185                }
186                return null;
187        }
188 
189        @Override
190        public Saveable[] getSaveables() {
191                ArrayList<MySaveable> result = new ArrayList<MySaveable>();
192                for (Resource r : (List<Resource>) rs.getResources())
193                {
194                   result.add(new MySaveable(r));
195                }
196                return result.toArray(new Saveable[]{});
197        }
198};
199 
200 
201/**
202 * @author Snowball
203 * This class is OBSOLETE and only left for demonstration purposes.
204 */
205public class PCMNavigatorContentProvider implements ITreeContentProvider, IAdaptable {
206 
207        private Object input;
208        final protected TransactionalEditingDomain editingDomain = null;
209//                TransactionalEditingDomain.Registry.INSTANCE
210//                .getEditingDomain(EditingDomainFactory.EDITING_DOMAIN_ID);
211        private StructuredViewer viewer;
212        private ComposedAdapterFactory adapterFactory;
213        private AdapterFactoryContentProvider contentProvider;
214        private MySaveablesProvider saveProvider = null;
215        private Hashtable<IProject,LinkedRepositoriesNode> myLinkedRepositoriesNodes = new Hashtable<IProject,LinkedRepositoriesNode>();
216 
217        public PCMNavigatorContentProvider()
218        {
219                //saveProvider = new MySaveablesProvider(editingDomain.getResourceSet());
220                
221                EContentAdapter repositoryResourceListeners = new EContentAdapter() {
222                        public void notifyChanged(Notification notification) {
223                                if (notification.getNotifier() instanceof ResourceSet) {
224                                        switch (notification.getFeatureID(ResourceSet.class)) {
225                                        case ResourceSet.RESOURCE_SET__RESOURCES:
226                                                if (notification.getEventType() == Notification.ADD) {
227                                                        System.out.println("New Resource loaded...");
228                                                        viewer.refresh();
229                                                }
230                                                break;
231                                        }
232                                } else if (notification.getNotifier() instanceof Resource) {
233                                        switch (notification.getFeatureID(Resource.class)) {
234                                        case Resource.RESOURCE__IS_LOADED:
235                                                if (notification.getEventType() == Notification.SET) {
236                                                        System.out.println("New Resource loaded...");
237                                                        viewer.refresh();
238                                                }
239                                                break;
240                                        }
241                                }
242                                else {
243                                        super.notifyChanged(notification);
244                                }
245                        }
246                };
247                repositoryResourceListeners.setTarget(editingDomain.getResourceSet());
248                editingDomain.getResourceSet().eAdapters().add(
249                                repositoryResourceListeners);
250                
251                adapterFactory = new ComposedAdapterFactory();
252                adapterFactory
253                                .addAdapterFactory(new ResourceItemProviderAdapterFactory());
254                adapterFactory
255                                .addAdapterFactory(new RepositoryItemProviderAdapterFactory());
256                adapterFactory.addAdapterFactory(new SeffItemProviderAdapterFactory());
257                adapterFactory
258                                .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
259                
260                AdapterFactory decoratorFactory = new CategoryAwareItemProviderAdapterFactory(adapterFactory, new PalladioCategoryDescriptions());
261                
262                contentProvider = new AdapterFactoryContentProvider(decoratorFactory);
263        }
264 
265        /* (non-Javadoc)
266         * @see org.eclipse.jface.viewers.ITreeContentProvider#getChildren(java.lang.Object)
267         */
268        public Object[] getChildren(Object parentElement) {
269                if (parentElement instanceof IProject)
270                {
271                        ArrayList children = new ArrayList();
272                        children.add(myLinkedRepositoriesNodes.get(parentElement));
273                        return children.toArray();
274                }
275                if (parentElement instanceof LinkedRepositoriesNode)
276                {
277                        ArrayList resourceList = new ArrayList();
278                        for (Iterator it=editingDomain.getResourceSet().getResources().iterator();
279                                it.hasNext();)
280                        {
281                                Resource r = (Resource)it.next();
282                                if (!r.isLoaded())
283                                        try {
284                                                r.load(new HashMap());
285                                        } catch (IOException e) {
286                                                // TODO Auto-generated catch block
287                                                e.printStackTrace();
288                                        }
289                                if (r.isLoaded())
290                                {
291                                        Collection repositories = EcoreUtil.getObjectsByType(r.getContents(), RepositoryPackage.eINSTANCE.getRepository());
292                                        resourceList.addAll(repositories);
293                                }
294                        }
295                        return resourceList.toArray();
296                }
297                if (parentElement instanceof EObject || parentElement instanceof GenericCategoryItemProvider)
298                {
299                        return contentProvider.getChildren(parentElement);
300                }
301                return null;
302        }
303 
304        /* (non-Javadoc)
305         * @see org.eclipse.jface.viewers.ITreeContentProvider#getParent(java.lang.Object)
306         */
307        public Object getParent(Object element) {
308                if (element instanceof LinkedRepositoriesNode)
309                        return ((LinkedRepositoriesNode)element).getParent();
310                if (element instanceof EObject) {
311                        Object originalParent = contentProvider.getParent(element);
312                        if (originalParent instanceof Resource)
313                                return myLinkedRepositoriesNodes.get(ResourcesPlugin.getWorkspace().getRoot().getProjects()[0]); //TODO: Works only with one project in the workspace
314                        return originalParent;
315                }
316                return null;
317        }
318 
319        /* (non-Javadoc)
320         * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object)
321         */
322        public boolean hasChildren(Object element) {
323                if (getChildren(element) == null)
324                        return false;
325                return getChildren(element).length > 0;
326        }
327 
328        /* (non-Javadoc)
329         * @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
330         */
331        public Object[] getElements(Object inputElement) {
332                return getChildren(inputElement);
333        }
334 
335        /* (non-Javadoc)
336         * @see org.eclipse.jface.viewers.IContentProvider#dispose()
337         */
338        public void dispose() {
339        }
340 
341        /* (non-Javadoc)
342         * @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
343         */
344        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
345                input = newInput;
346                this.viewer = (StructuredViewer)viewer;
347                contentProvider.inputChanged(viewer, oldInput, newInput);
348                populateHashtable();
349        }
350 
351        private void 
352        populateHashtable() {
353                myLinkedRepositoriesNodes.clear();
354                for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects())
355                {
356                        myLinkedRepositoriesNodes.put(p,new LinkedRepositoriesNode(p));
357                }
358        }
359 
360        public Object getAdapter(Class adapter) {
361                //if (adapter == SaveablesProvider.class)
362                //        return saveProvider;
363                 return null;
364        }
365 
366}

[all classes][de.uka.ipd.sdq.pcmbench.navigator]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov