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

COVERAGE SUMMARY FOR SOURCE FILE [PalladioComponentModelElementChooserDialog.java]

nameclass, %method, %block, %line, %
PalladioComponentModelElementChooserDialog.java0%   (0/5)0%   (0/35)0%   (0/533)0%   (0/150)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioComponentModelElementChooserDialog0%   (0/1)0%   (0/13)0%   (0/160)0%   (0/42)
PalladioComponentModelElementChooserDialog (Shell, View): void 0%   (0/1)0%   (0/17)0%   (0/6)
access$0 (PalladioComponentModelElementChooserDialog): TransactionalEditingDo... 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (PalladioComponentModelElementChooserDialog, IFile): boolean 0%   (0/1)0%   (0/4)0%   (0/1)
access$2 (PalladioComponentModelElementChooserDialog): View 0%   (0/1)0%   (0/3)0%   (0/1)
access$3 (PalladioComponentModelElementChooserDialog, boolean): void 0%   (0/1)0%   (0/4)0%   (0/1)
access$4 (PalladioComponentModelElementChooserDialog, URI): void 0%   (0/1)0%   (0/4)0%   (0/1)
createButtonBar (Composite): Control 0%   (0/1)0%   (0/9)0%   (0/3)
createDialogArea (Composite): Control 0%   (0/1)0%   (0/14)0%   (0/6)
createModelBrowser (Composite): void 0%   (0/1)0%   (0/61)0%   (0/11)
getSelectedModelElementURI (): URI 0%   (0/1)0%   (0/3)0%   (0/1)
isValidModelFile (IFile): boolean 0%   (0/1)0%   (0/8)0%   (0/2)
open (): int 0%   (0/1)0%   (0/24)0%   (0/7)
setOkButtonEnabled (boolean): void 0%   (0/1)0%   (0/6)0%   (0/2)
     
class PalladioComponentModelElementChooserDialog$ModelElementsTreeContentProvider0%   (0/1)0%   (0/8)0%   (0/174)0%   (0/49)
PalladioComponentModelElementChooserDialog$ModelElementsTreeContentProvider (... 0%   (0/1)0%   (0/18)0%   (0/4)
PalladioComponentModelElementChooserDialog$ModelElementsTreeContentProvider (... 0%   (0/1)0%   (0/4)0%   (0/1)
dispose (): void 0%   (0/1)0%   (0/7)0%   (0/3)
getChildren (Object): Object [] 0%   (0/1)0%   (0/59)0%   (0/19)
getElements (Object): Object [] 0%   (0/1)0%   (0/7)0%   (0/3)
getParent (Object): Object 0%   (0/1)0%   (0/43)0%   (0/12)
hasChildren (Object): boolean 0%   (0/1)0%   (0/23)0%   (0/4)
inputChanged (Viewer, Object, Object): void 0%   (0/1)0%   (0/13)0%   (0/4)
     
class PalladioComponentModelElementChooserDialog$ModelElementsTreeLabelProvider0%   (0/1)0%   (0/8)0%   (0/94)0%   (0/22)
PalladioComponentModelElementChooserDialog$ModelElementsTreeLabelProvider (Pa... 0%   (0/1)0%   (0/18)0%   (0/4)
PalladioComponentModelElementChooserDialog$ModelElementsTreeLabelProvider (Pa... 0%   (0/1)0%   (0/4)0%   (0/1)
addListener (ILabelProviderListener): void 0%   (0/1)0%   (0/9)0%   (0/3)
dispose (): void 0%   (0/1)0%   (0/7)0%   (0/3)
getImage (Object): Image 0%   (0/1)0%   (0/14)0%   (0/3)
getText (Object): String 0%   (0/1)0%   (0/17)0%   (0/3)
isLabelProperty (Object, String): boolean 0%   (0/1)0%   (0/16)0%   (0/3)
removeListener (ILabelProviderListener): void 0%   (0/1)0%   (0/9)0%   (0/3)
     
class PalladioComponentModelElementChooserDialog$ModelFilesFilter0%   (0/1)0%   (0/3)0%   (0/28)0%   (0/7)
PalladioComponentModelElementChooserDialog$ModelFilesFilter (PalladioComponen... 0%   (0/1)0%   (0/6)0%   (0/1)
PalladioComponentModelElementChooserDialog$ModelFilesFilter (PalladioComponen... 0%   (0/1)0%   (0/4)0%   (0/1)
select (Viewer, Object, Object): boolean 0%   (0/1)0%   (0/18)0%   (0/6)
     
class PalladioComponentModelElementChooserDialog$OkButtonEnabler0%   (0/1)0%   (0/3)0%   (0/77)0%   (0/30)
PalladioComponentModelElementChooserDialog$OkButtonEnabler (PalladioComponent... 0%   (0/1)0%   (0/6)0%   (0/1)
PalladioComponentModelElementChooserDialog$OkButtonEnabler (PalladioComponent... 0%   (0/1)0%   (0/4)0%   (0/1)
selectionChanged (SelectionChangedEvent): void 0%   (0/1)0%   (0/67)0%   (0/29)

1/*
2 * Copyright 2007, IPD, SDQ, University of Karlsruhe
3 */
4package de.uka.ipd.sdq.pcm.gmf.repository.part;
5 
6import java.util.Collections;
7import java.util.Iterator;
8 
9import org.eclipse.core.resources.IContainer;
10import org.eclipse.core.resources.IFile;
11import org.eclipse.core.resources.ResourcesPlugin;
12import org.eclipse.core.runtime.IPath;
13import org.eclipse.core.runtime.Path;
14import org.eclipse.emf.common.util.URI;
15import org.eclipse.emf.common.util.WrappedException;
16import org.eclipse.emf.ecore.EObject;
17import org.eclipse.emf.ecore.resource.Resource;
18import org.eclipse.emf.ecore.resource.ResourceSet;
19import org.eclipse.emf.ecore.util.EcoreUtil;
20import org.eclipse.emf.ecore.util.FeatureMap;
21import org.eclipse.emf.edit.provider.IWrapperItemProvider;
22import org.eclipse.emf.edit.ui.provider.AdapterFactoryContentProvider;
23import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
24import org.eclipse.emf.transaction.TransactionalEditingDomain;
25import org.eclipse.gmf.runtime.diagram.core.services.ViewService;
26import org.eclipse.gmf.runtime.diagram.core.util.ViewUtil;
27import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
28import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
29import org.eclipse.gmf.runtime.notation.Node;
30import org.eclipse.gmf.runtime.notation.View;
31import org.eclipse.jface.dialogs.Dialog;
32import org.eclipse.jface.dialogs.IDialogConstants;
33import org.eclipse.jface.viewers.ILabelProvider;
34import org.eclipse.jface.viewers.ILabelProviderListener;
35import org.eclipse.jface.viewers.ISelectionChangedListener;
36import org.eclipse.jface.viewers.IStructuredSelection;
37import org.eclipse.jface.viewers.ITreeContentProvider;
38import org.eclipse.jface.viewers.SelectionChangedEvent;
39import org.eclipse.jface.viewers.TreeViewer;
40import org.eclipse.jface.viewers.Viewer;
41import org.eclipse.jface.viewers.ViewerFilter;
42import org.eclipse.swt.SWT;
43import org.eclipse.swt.graphics.Image;
44import org.eclipse.swt.layout.GridData;
45import org.eclipse.swt.widgets.Composite;
46import org.eclipse.swt.widgets.Control;
47import org.eclipse.swt.widgets.Shell;
48import org.eclipse.ui.model.WorkbenchContentProvider;
49import org.eclipse.ui.model.WorkbenchLabelProvider;
50 
51/**
52 * @generated
53 */
54public class PalladioComponentModelElementChooserDialog extends Dialog {
55 
56        /**
57         * @generated
58         */
59        private TreeViewer myTreeViewer;
60 
61        /**
62         * @generated
63         */
64        private URI mySelectedModelElementURI;
65 
66        /**
67         * @generated
68         */
69        private View myView;
70 
71        /**
72         * @generated
73         */
74        private TransactionalEditingDomain myEditingDomain = GMFEditingDomainFactory.INSTANCE
75                        .createEditingDomain();
76 
77        /**
78         * @generated
79         */
80        public PalladioComponentModelElementChooserDialog(Shell parentShell,
81                        View view) {
82                super(parentShell);
83                setShellStyle(getShellStyle() | SWT.RESIZE);
84                myView = view;
85        }
86 
87        /**
88         * @generated
89         */
90        protected Control createDialogArea(Composite parent) {
91                Composite composite = (Composite) super.createDialogArea(parent);
92                getShell()
93                                .setText(
94                                                Messages.PalladioComponentModelElementChooserDialog_SelectModelElementTitle);
95                createModelBrowser(composite);
96                return composite;
97        }
98 
99        /**
100         * @generated
101         */
102        protected Control createButtonBar(Composite parent) {
103                Control buttonBar = super.createButtonBar(parent);
104                setOkButtonEnabled(false);
105                return buttonBar;
106        }
107 
108        /**
109         * @generated
110         */
111        private void createModelBrowser(Composite composite) {
112                myTreeViewer = new TreeViewer(composite, SWT.SINGLE | SWT.H_SCROLL
113                                | SWT.V_SCROLL | SWT.BORDER);
114                GridData layoutData = new GridData(GridData.FILL_BOTH);
115                layoutData.heightHint = 300;
116                layoutData.widthHint = 300;
117                myTreeViewer.getTree().setLayoutData(layoutData);
118                myTreeViewer.setContentProvider(new ModelElementsTreeContentProvider());
119                myTreeViewer.setLabelProvider(new ModelElementsTreeLabelProvider());
120                myTreeViewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
121                myTreeViewer.addFilter(new ModelFilesFilter());
122                myTreeViewer.addSelectionChangedListener(new OkButtonEnabler());
123        }
124 
125        /**
126         * @generated
127         */
128        private void setOkButtonEnabled(boolean enabled) {
129                getButton(IDialogConstants.OK_ID).setEnabled(enabled);
130        }
131 
132        /**
133         * @generated
134         */
135        private boolean isValidModelFile(IFile file) {
136                String fileExtension = file.getFullPath().getFileExtension();
137                return "repository".equals(fileExtension); //$NON-NLS-1$
138        }
139 
140        /**
141         * @generated
142         */
143        public URI getSelectedModelElementURI() {
144                return mySelectedModelElementURI;
145        }
146 
147        /**
148         * @generated
149         */
150        public int open() {
151                int result = super.open();
152                for (Iterator it = myEditingDomain.getResourceSet().getResources()
153                                .iterator(); it.hasNext();) {
154                        Resource resource = (Resource) it.next();
155                        resource.unload();
156                }
157                myEditingDomain.dispose();
158                return result;
159        }
160 
161        /**
162         * @generated
163         */
164        private class ModelElementsTreeContentProvider implements
165                        ITreeContentProvider {
166 
167                /**
168                 * @generated
169                 */
170                private ITreeContentProvider myWorkbenchContentProvider = new WorkbenchContentProvider();
171 
172                /**
173                 * @generated
174                 */
175                private AdapterFactoryContentProvider myAdapterFctoryContentProvier = new AdapterFactoryContentProvider(
176                                PalladioComponentModelRepositoryDiagramEditorPlugin
177                                                .getInstance().getItemProvidersAdapterFactory());
178 
179                /**
180                 * @generated
181                 */
182                public Object[] getChildren(Object parentElement) {
183                        Object[] result = myWorkbenchContentProvider
184                                        .getChildren(parentElement);
185                        if (result != null && result.length > 0) {
186                                return result;
187                        }
188                        if (parentElement instanceof IFile) {
189                                IFile modelFile = (IFile) parentElement;
190                                IPath resourcePath = modelFile.getFullPath();
191                                ResourceSet resourceSet = myEditingDomain.getResourceSet();
192                                try {
193                                        Resource modelResource = resourceSet.getResource(URI
194                                                        .createPlatformResourceURI(resourcePath.toString(),
195                                                                        true), true);
196                                        return myAdapterFctoryContentProvier
197                                                        .getChildren(modelResource);
198                                } catch (WrappedException e) {
199                                        PalladioComponentModelRepositoryDiagramEditorPlugin
200                                                        .getInstance()
201                                                        .logError(
202                                                                        "Unable to load resource: " + resourcePath.toString(), e); //$NON-NLS-1$
203                                }
204                                return Collections.EMPTY_LIST.toArray();
205                        }
206                        return myAdapterFctoryContentProvier.getChildren(parentElement);
207                }
208 
209                /**
210                 * @generated
211                 */
212                public Object getParent(Object element) {
213                        Object parent = myWorkbenchContentProvider.getParent(element);
214                        if (parent != null) {
215                                return parent;
216                        }
217                        if (element instanceof EObject) {
218                                EObject eObject = (EObject) element;
219                                if (eObject.eContainer() == null
220                                                && eObject.eResource().getURI().isFile()) {
221                                        String path = eObject.eResource().getURI().path();
222                                        return ResourcesPlugin.getWorkspace().getRoot()
223                                                        .getFileForLocation(new Path(path));
224                                }
225                                return myAdapterFctoryContentProvier.getParent(eObject);
226                        }
227                        return null;
228                }
229 
230                /**
231                 * @generated
232                 */
233                public boolean hasChildren(Object element) {
234                        if (element instanceof IFile) {
235                                return isValidModelFile((IFile) element);
236                        }
237                        return myWorkbenchContentProvider.hasChildren(element)
238                                        || myAdapterFctoryContentProvier.hasChildren(element);
239                }
240 
241                /**
242                 * @generated
243                 */
244                public Object[] getElements(Object inputElement) {
245                        Object[] elements = myWorkbenchContentProvider
246                                        .getElements(inputElement);
247                        return elements;
248                }
249 
250                /**
251                 * @generated
252                 */
253                public void dispose() {
254                        myWorkbenchContentProvider.dispose();
255                        myAdapterFctoryContentProvier.dispose();
256                }
257 
258                /**
259                 * @generated
260                 */
261                public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
262                        myWorkbenchContentProvider.inputChanged(viewer, oldInput, newInput);
263                        myAdapterFctoryContentProvier.inputChanged(viewer, oldInput,
264                                        newInput);
265                }
266 
267        }
268 
269        /**
270         * @generated
271         */
272        private class ModelElementsTreeLabelProvider implements ILabelProvider {
273 
274                /**
275                 * @generated
276                 */
277                private WorkbenchLabelProvider myWorkbenchLabelProvider = new WorkbenchLabelProvider();
278 
279                /**
280                 * @generated
281                 */
282                private AdapterFactoryLabelProvider myAdapterFactoryLabelProvider = new AdapterFactoryLabelProvider(
283                                PalladioComponentModelRepositoryDiagramEditorPlugin
284                                                .getInstance().getItemProvidersAdapterFactory());
285 
286                /**
287                 * @generated
288                 */
289                public Image getImage(Object element) {
290                        Image result = myWorkbenchLabelProvider.getImage(element);
291                        return result != null ? result : myAdapterFactoryLabelProvider
292                                        .getImage(element);
293                }
294 
295                /**
296                 * @generated
297                 */
298                public String getText(Object element) {
299                        String result = myWorkbenchLabelProvider.getText(element);
300                        return result != null && result.length() > 0 ? result
301                                        : myAdapterFactoryLabelProvider.getText(element);
302                }
303 
304                /**
305                 * @generated
306                 */
307                public void addListener(ILabelProviderListener listener) {
308                        myWorkbenchLabelProvider.addListener(listener);
309                        myAdapterFactoryLabelProvider.addListener(listener);
310                }
311 
312                /**
313                 * @generated
314                 */
315                public void dispose() {
316                        myWorkbenchLabelProvider.dispose();
317                        myAdapterFactoryLabelProvider.dispose();
318                }
319 
320                /**
321                 * @generated
322                 */
323                public boolean isLabelProperty(Object element, String property) {
324                        return myWorkbenchLabelProvider.isLabelProperty(element, property)
325                                        || myAdapterFactoryLabelProvider.isLabelProperty(element,
326                                                        property);
327                }
328 
329                /**
330                 * @generated
331                 */
332                public void removeListener(ILabelProviderListener listener) {
333                        myWorkbenchLabelProvider.removeListener(listener);
334                        myAdapterFactoryLabelProvider.removeListener(listener);
335                }
336 
337        }
338 
339        /**
340         * @generated
341         */
342        private class ModelFilesFilter extends ViewerFilter {
343 
344                /**
345                 * @generated
346                 */
347                public boolean select(Viewer viewer, Object parentElement,
348                                Object element) {
349                        if (element instanceof IContainer) {
350                                return true;
351                        }
352                        if (element instanceof IFile) {
353                                IFile file = (IFile) element;
354                                return isValidModelFile(file);
355                        }
356                        return true;
357                }
358 
359        }
360 
361        /**
362         * @generated
363         */
364        private class OkButtonEnabler implements ISelectionChangedListener {
365 
366                /**
367                 * @generated
368                 */
369                public void selectionChanged(SelectionChangedEvent event) {
370                        if (event.getSelection() instanceof IStructuredSelection) {
371                                IStructuredSelection selection = (IStructuredSelection) event
372                                                .getSelection();
373                                if (selection.size() == 1) {
374                                        Object selectedElement = selection.getFirstElement();
375                                        if (selectedElement instanceof IWrapperItemProvider) {
376                                                selectedElement = ((IWrapperItemProvider) selectedElement)
377                                                                .getValue();
378                                        }
379                                        if (selectedElement instanceof FeatureMap.Entry) {
380                                                selectedElement = ((FeatureMap.Entry) selectedElement)
381                                                                .getValue();
382                                        }
383                                        if (selectedElement instanceof EObject) {
384                                                EObject selectedModelElement = (EObject) selectedElement;
385                                                setOkButtonEnabled(ViewService
386                                                                .getInstance()
387                                                                .provides(
388                                                                                Node.class,
389                                                                                new EObjectAdapter(selectedModelElement),
390                                                                                myView,
391                                                                                null,
392                                                                                ViewUtil.APPEND,
393                                                                                true,
394                                                                                PalladioComponentModelRepositoryDiagramEditorPlugin.DIAGRAM_PREFERENCES_HINT));
395                                                mySelectedModelElementURI = EcoreUtil
396                                                                .getURI(selectedModelElement);
397                                                return;
398                                        }
399                                }
400                        }
401                        mySelectedModelElementURI = null;
402                        setOkButtonEnabled(false);
403                }
404 
405        }
406 
407}

[all classes][de.uka.ipd.sdq.pcm.gmf.repository.part]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov