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

COVERAGE SUMMARY FOR SOURCE FILE [PcmResourceSelectorPage.java]

nameclass, %method, %block, %line, %
PcmResourceSelectorPage.java0%   (0/2)0%   (0/11)0%   (0/236)0%   (0/63)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ResourceSelectorPage0%   (0/1)0%   (0/9)0%   (0/193)0%   (0/52)
ResourceSelectorPage (String, EObject): void 0%   (0/1)0%   (0/13)0%   (0/5)
access$0 (ResourceSelectorPage): Text 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (ResourceSelectorPage): void 0%   (0/1)0%   (0/3)0%   (0/1)
createControl (Composite): void 0%   (0/1)0%   (0/35)0%   (0/9)
createPageContent (Composite): void 0%   (0/1)0%   (0/88)0%   (0/21)
doValidatePage (): boolean 0%   (0/1)0%   (0/7)0%   (0/1)
getResolvedObject (): EObject 0%   (0/1)0%   (0/3)0%   (0/1)
resolveSelection (): void 0%   (0/1)0%   (0/28)0%   (0/8)
validatePage (): boolean 0%   (0/1)0%   (0/13)0%   (0/5)
     
class ResourceSelectorPage$10%   (0/1)0%   (0/2)0%   (0/43)0%   (0/12)
ResourceSelectorPage$1 (ResourceSelectorPage): void 0%   (0/1)0%   (0/6)0%   (0/2)
widgetSelected (SelectionEvent): void 0%   (0/1)0%   (0/37)0%   (0/10)

1package de.uka.ipd.sdq.pcm.gmf.allocation.part;
2 
3import org.eclipse.emf.common.util.URI;
4import org.eclipse.emf.common.util.WrappedException;
5import org.eclipse.emf.ecore.EObject;
6import org.eclipse.emf.ecore.resource.Resource;
7import org.eclipse.emf.ecore.resource.ResourceSet;
8import org.eclipse.emf.edit.ui.action.LoadResourceAction.LoadResourceDialog;
9import org.eclipse.emf.transaction.TransactionalEditingDomain;
10import org.eclipse.gmf.runtime.emf.core.GMFEditingDomainFactory;
11import org.eclipse.jface.wizard.WizardPage;
12import org.eclipse.swt.SWT;
13import org.eclipse.swt.events.SelectionAdapter;
14import org.eclipse.swt.events.SelectionEvent;
15import org.eclipse.swt.layout.GridData;
16import org.eclipse.swt.layout.GridLayout;
17import org.eclipse.swt.widgets.Button;
18import org.eclipse.swt.widgets.Composite;
19import org.eclipse.swt.widgets.Label;
20import org.eclipse.swt.widgets.Shell;
21import org.eclipse.swt.widgets.Text;
22 
23/**
24 * This wizard allows the user to select a resource. It can be passed an
25 * already selected resource which then can be changed. A value of null
26 * will leave it up to the user to locate the resource.
27 * 
28 * The dialog will only succeed if a valid resource file has been selected.
29 */
30class ResourceSelectorPage extends WizardPage {
31        private Text mySelectionText;
32        private EObject myResolvedObject;
33 
34        /**
35         * @return a valid resource, or null if no valid one has been selected
36         */        
37        protected EObject getResolvedObject() {
38                return myResolvedObject;
39        }
40 
41        protected ResourceSelectorPage(String name, EObject selectedResource) {
42                super(name);
43                setTitle("Diagram resource");
44                setDescription("Select the resource to be used for the diagram.");
45                myResolvedObject = selectedResource;
46        }
47 
48        public void createControl(Composite parent) {
49                initializeDialogUnits(parent);
50                Composite topLevel = new Composite(parent, SWT.NONE);
51                topLevel.setLayout(new GridLayout());
52                topLevel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL
53                                | GridData.HORIZONTAL_ALIGN_FILL));
54                topLevel.setFont(parent.getFont());
55                setControl(topLevel);
56                createPageContent(topLevel);
57                setPageComplete(doValidatePage());
58        }
59        
60        /**
61         * creates the SWT widgets used to select and display the resource and initializes them
62         */
63        private void createPageContent(Composite parent) {
64                Composite panel = new Composite(parent, SWT.NONE);
65                panel.setLayoutData(new GridData(GridData.FILL_BOTH));
66                GridLayout layout = new GridLayout();
67                panel.setLayout(layout);
68 
69                Label label = new Label(panel, SWT.NONE);
70                label.setText("Selected resource:");
71                label.setLayoutData(new GridData(
72                                GridData.HORIZONTAL_ALIGN_BEGINNING));
73 
74                mySelectionText = new Text(panel, SWT.READ_ONLY);
75                mySelectionText.setText("none");
76                if (myResolvedObject != null) {
77                        mySelectionText.setText(myResolvedObject.eResource().getURI().path());
78                }
79                mySelectionText.setLayoutData(new GridData(
80                                GridData.CENTER));
81                mySelectionText.pack();
82 
83                Button button = new Button(panel, SWT.NONE);
84                button.setText("Change");
85                button.setLayoutData(new GridData(
86                                GridData.END));
87 
88                button.addSelectionListener(new SelectionAdapter(){
89 
90                        /* (non-Javadoc)
91                         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
92                         */
93                        @Override
94                        public void widgetSelected(SelectionEvent e) {
95                                Shell shell = e.display.getActiveShell();
96                                LoadResourceDialog dialog = new LoadResourceDialog(shell);
97                                dialog.open();
98                                String uri = dialog.getURIText();
99                                if (uri != null){
100                                        mySelectionText.setText(dialog.getURIText());
101                                }
102                                mySelectionText.pack();
103                                resolveSelection();
104                                setPageComplete(validatePage());
105                        }
106                        
107                });
108        }
109 
110        /** 
111         * @return true, if a valid resource file has been selected and resolved
112         */        
113        protected boolean validatePage() {
114                if (myResolvedObject == null) {
115                        setErrorMessage("No or invalid resource selected");
116                        return false;
117                }
118 
119                setErrorMessage(null);
120                return true;
121        }
122        
123        protected boolean doValidatePage() {
124                return (myResolvedObject != null);
125        }
126 
127        /**
128         * checks if the selected file is a valid resource
129         */        
130        private void resolveSelection() {
131                myResolvedObject = null;
132                TransactionalEditingDomain editingDomain = GMFEditingDomainFactory.INSTANCE
133                .createEditingDomain();
134                ResourceSet resourceSet = editingDomain.getResourceSet();
135 
136                try {
137                        Resource resource = resourceSet.getResource(URI.createURI(mySelectionText.getText(),true), true);
138                        myResolvedObject = (EObject) resource.getContents().get(0);
139 
140                } catch (WrappedException ex) {
141                        //do nothing
142                }        
143        }
144}

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