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

COVERAGE SUMMARY FOR SOURCE FILE [ValidateAction.java]

nameclass, %method, %block, %line, %
ValidateAction.java0%   (0/4)0%   (0/20)0%   (0/444)0%   (0/141)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ValidateAction0%   (0/1)0%   (0/14)0%   (0/405)0%   (0/134)
ValidateAction (IWorkbenchPage): void 0%   (0/1)0%   (0/9)0%   (0/4)
access$0 (DiagramEditPart, View): void 0%   (0/1)0%   (0/4)0%   (0/1)
addMarker (EditPartViewer, IFile, String, String, String, int): void 0%   (0/1)0%   (0/11)0%   (0/5)
collectTargetElements (Diagnostic, Set, List): Set 0%   (0/1)0%   (0/52)0%   (0/13)
collectTargetElements (IStatus, Set, List): Set 0%   (0/1)0%   (0/36)0%   (0/10)
createMarkers (IFile, Diagnostic, DiagramEditPart): void 0%   (0/1)0%   (0/74)0%   (0/24)
createMarkers (IFile, IStatus, DiagramEditPart): void 0%   (0/1)0%   (0/56)0%   (0/16)
diagnosticToStatusSeverity (int): int 0%   (0/1)0%   (0/24)0%   (0/10)
run (): void 0%   (0/1)0%   (0/29)0%   (0/10)
runEMFValidator (View): Diagnostic 0%   (0/1)0%   (0/15)0%   (0/4)
runNonUIValidation (View): void 0%   (0/1)0%   (0/9)0%   (0/4)
runValidation (DiagramEditPart, View): void 0%   (0/1)0%   (0/15)0%   (0/7)
runValidation (View): void 0%   (0/1)0%   (0/27)0%   (0/13)
validate (DiagramEditPart, View): void 0%   (0/1)0%   (0/44)0%   (0/13)
     
class ValidateAction$10%   (0/1)0%   (0/2)0%   (0/17)0%   (0/5)
ValidateAction$1 (ValidateAction, IDiagramWorkbenchPart): void 0%   (0/1)0%   (0/9)0%   (0/2)
run (IProgressMonitor): void 0%   (0/1)0%   (0/8)0%   (0/3)
     
class ValidateAction$20%   (0/1)0%   (0/2)0%   (0/15)0%   (0/4)
ValidateAction$2 (DiagramEditPart, View): void 0%   (0/1)0%   (0/9)0%   (0/2)
run (): void 0%   (0/1)0%   (0/6)0%   (0/2)
     
class ValidateAction$30%   (0/1)0%   (0/2)0%   (0/7)0%   (0/3)
ValidateAction$3 (): void 0%   (0/1)0%   (0/3)0%   (0/2)
getObjectLabel (EObject): String 0%   (0/1)0%   (0/4)0%   (0/1)

1/*
2 * Copyright 2006 SDQ Research Group, University of Karlsruhe (TH)
3 */
4package de.uka.ipd.sdq.pcm.gmf.seff.part;
5 
6import java.lang.reflect.InvocationTargetException;
7import java.util.ArrayList;
8import java.util.HashSet;
9import java.util.Iterator;
10import java.util.List;
11import java.util.Set;
12 
13import org.eclipse.core.resources.IFile;
14import org.eclipse.core.runtime.IProgressMonitor;
15import org.eclipse.core.runtime.IStatus;
16import org.eclipse.core.runtime.NullProgressMonitor;
17import org.eclipse.emf.common.util.Diagnostic;
18import org.eclipse.emf.ecore.EObject;
19import org.eclipse.emf.ecore.util.Diagnostician;
20import org.eclipse.emf.transaction.TransactionalEditingDomain;
21import org.eclipse.emf.transaction.util.TransactionUtil;
22import org.eclipse.emf.validation.model.EvaluationMode;
23import org.eclipse.emf.validation.model.IConstraintStatus;
24import org.eclipse.emf.validation.service.IBatchValidator;
25import org.eclipse.emf.validation.service.ModelValidationService;
26import org.eclipse.emf.workspace.util.WorkspaceSynchronizer;
27import org.eclipse.gef.EditPartViewer;
28import org.eclipse.gmf.runtime.diagram.ui.OffscreenEditPartFactory;
29import org.eclipse.gmf.runtime.diagram.ui.editparts.DiagramEditPart;
30import org.eclipse.gmf.runtime.diagram.ui.parts.IDiagramWorkbenchPart;
31import org.eclipse.gmf.runtime.emf.core.util.EMFCoreUtil;
32import org.eclipse.gmf.runtime.notation.View;
33import org.eclipse.jface.action.Action;
34import org.eclipse.jface.operation.IRunnableWithProgress;
35import org.eclipse.ui.IEditorPart;
36import org.eclipse.ui.IWorkbenchPage;
37import org.eclipse.ui.IWorkbenchPart;
38import org.eclipse.ui.PlatformUI;
39import org.eclipse.ui.actions.WorkspaceModifyDelegatingOperation;
40 
41import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelMarkerNavigationProvider;
42import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelValidationProvider;
43 
44/**
45 * @generated
46 */
47public class ValidateAction extends Action {
48 
49        /**
50         * @generated
51         */
52        private IWorkbenchPage page;
53 
54        /**
55         * @generated
56         */
57        public ValidateAction(IWorkbenchPage page) {
58                setText(Messages.ValidateActionMessage);
59                this.page = page;
60        }
61 
62        /**
63         * @generated
64         */
65        public void run() {
66                IWorkbenchPart workbenchPart = page.getActivePart();
67                if (workbenchPart instanceof IDiagramWorkbenchPart) {
68                        final IDiagramWorkbenchPart part = (IDiagramWorkbenchPart) workbenchPart;
69                        try {
70                                new WorkspaceModifyDelegatingOperation(
71                                                new IRunnableWithProgress() {
72 
73                                                        public void run(IProgressMonitor monitor)
74                                                                        throws InterruptedException,
75                                                                        InvocationTargetException {
76                                                                runValidation(part.getDiagramEditPart(), part
77                                                                                .getDiagram());
78                                                        }
79                                                }).run(new NullProgressMonitor());
80                        } catch (Exception e) {
81                                PalladioComponentModelSeffDiagramEditorPlugin.getInstance()
82                                                .logError("Validation action failed", e); //$NON-NLS-1$
83                        }
84                }
85        }
86 
87        /**
88         * @generated
89         */
90        public static void runValidation(View view) {
91                try {
92                        if (PalladioComponentModelDiagramEditorUtil.openDiagram(view
93                                        .eResource())) {
94                                IEditorPart editorPart = PlatformUI.getWorkbench()
95                                                .getActiveWorkbenchWindow().getActivePage()
96                                                .getActiveEditor();
97                                if (editorPart instanceof IDiagramWorkbenchPart) {
98                                        runValidation(((IDiagramWorkbenchPart) editorPart)
99                                                        .getDiagramEditPart(), view);
100                                } else {
101                                        runNonUIValidation(view);
102                                }
103                        }
104                } catch (Exception e) {
105                        PalladioComponentModelSeffDiagramEditorPlugin.getInstance()
106                                        .logError("Validation action failed", e); //$NON-NLS-1$
107                }
108        }
109 
110        /**
111         * @generated
112         */
113        public static void runNonUIValidation(View view) {
114                DiagramEditPart diagramEditPart = OffscreenEditPartFactory
115                                .getInstance().createDiagramEditPart(view.getDiagram());
116                runValidation(diagramEditPart, view);
117        }
118 
119        /**
120         * @generated
121         */
122        public static void runValidation(DiagramEditPart diagramEditPart, View view) {
123                final DiagramEditPart fpart = diagramEditPart;
124                final View fview = view;
125                TransactionalEditingDomain txDomain = TransactionUtil
126                                .getEditingDomain(view);
127                PalladioComponentModelValidationProvider.runWithConstraints(txDomain,
128                                new Runnable() {
129 
130                                        public void run() {
131                                                validate(fpart, fview);
132                                        }
133                                });
134        }
135 
136        /**
137         * @generated
138         */
139        private static Diagnostic runEMFValidator(View target) {
140                if (target.isSetElement() && target.getElement() != null) {
141                        return new Diagnostician() {
142 
143                                public String getObjectLabel(EObject eObject) {
144                                        return EMFCoreUtil.getQualifiedName(eObject, true);
145                                }
146                        }.validate(target.getElement());
147                }
148                return Diagnostic.OK_INSTANCE;
149        }
150 
151        /**
152         * @generated
153         */
154        private static void validate(DiagramEditPart diagramEditPart, View view) {
155                IFile target = view.eResource() != null ? WorkspaceSynchronizer
156                                .getFile(view.eResource()) : null;
157                if (target != null) {
158                        PalladioComponentModelMarkerNavigationProvider
159                                        .deleteMarkers(target);
160                }
161                Diagnostic diagnostic = runEMFValidator(view);
162                createMarkers(target, diagnostic, diagramEditPart);
163                IBatchValidator validator = (IBatchValidator) ModelValidationService
164                                .getInstance().newValidator(EvaluationMode.BATCH);
165                validator.setIncludeLiveConstraints(true);
166                if (view.isSetElement() && view.getElement() != null) {
167                        IStatus status = validator.validate(view.getElement());
168                        createMarkers(target, status, diagramEditPart);
169                }
170        }
171 
172        /**
173         * @generated
174         */
175        private static void createMarkers(IFile target, IStatus validationStatus,
176                        DiagramEditPart diagramEditPart) {
177                if (validationStatus.isOK()) {
178                        return;
179                }
180                final IStatus rootStatus = validationStatus;
181                List allStatuses = new ArrayList();
182                PalladioComponentModelDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new PalladioComponentModelDiagramEditorUtil.LazyElement2ViewMap(
183                                diagramEditPart.getDiagramView(), collectTargetElements(
184                                                rootStatus, new HashSet(), allStatuses));
185                for (Iterator it = allStatuses.iterator(); it.hasNext();) {
186                        IConstraintStatus nextStatus = (IConstraintStatus) it.next();
187                        View view = PalladioComponentModelDiagramEditorUtil.findView(
188                                        diagramEditPart, nextStatus.getTarget(), element2ViewMap);
189                        addMarker(diagramEditPart.getViewer(), target, view.eResource()
190                                        .getURIFragment(view), EMFCoreUtil.getQualifiedName(
191                                        nextStatus.getTarget(), true), nextStatus.getMessage(),
192                                        nextStatus.getSeverity());
193                }
194        }
195 
196        /**
197         * @generated
198         */
199        private static void createMarkers(IFile target,
200                        Diagnostic emfValidationStatus, DiagramEditPart diagramEditPart) {
201                if (emfValidationStatus.getSeverity() == Diagnostic.OK) {
202                        return;
203                }
204                final Diagnostic rootStatus = emfValidationStatus;
205                List allDiagnostics = new ArrayList();
206                PalladioComponentModelDiagramEditorUtil.LazyElement2ViewMap element2ViewMap = new PalladioComponentModelDiagramEditorUtil.LazyElement2ViewMap(
207                                diagramEditPart.getDiagramView(), collectTargetElements(
208                                                rootStatus, new HashSet(), allDiagnostics));
209                for (Iterator it = emfValidationStatus.getChildren().iterator(); it
210                                .hasNext();) {
211                        Diagnostic nextDiagnostic = (Diagnostic) it.next();
212                        List data = nextDiagnostic.getData();
213                        if (data != null && !data.isEmpty()
214                                        && data.get(0) instanceof EObject) {
215                                EObject element = (EObject) data.get(0);
216                                View view = PalladioComponentModelDiagramEditorUtil.findView(
217                                                diagramEditPart, element, element2ViewMap);
218                                addMarker(
219                                                diagramEditPart.getViewer(),
220                                                target,
221                                                view.eResource().getURIFragment(view),
222                                                EMFCoreUtil.getQualifiedName(element, true),
223                                                nextDiagnostic.getMessage(),
224                                                diagnosticToStatusSeverity(nextDiagnostic.getSeverity()));
225                        }
226                }
227        }
228 
229        /**
230         * @generated
231         */
232        private static void addMarker(EditPartViewer viewer, IFile target,
233                        String elementId, String location, String message,
234                        int statusSeverity) {
235                if (target == null) {
236                        return;
237                }
238                PalladioComponentModelMarkerNavigationProvider.addMarker(target,
239                                elementId, location, message, statusSeverity);
240        }
241 
242        /**
243         * @generated
244         */
245        private static int diagnosticToStatusSeverity(int diagnosticSeverity) {
246                if (diagnosticSeverity == Diagnostic.OK) {
247                        return IStatus.OK;
248                } else if (diagnosticSeverity == Diagnostic.INFO) {
249                        return IStatus.INFO;
250                } else if (diagnosticSeverity == Diagnostic.WARNING) {
251                        return IStatus.WARNING;
252                } else if (diagnosticSeverity == Diagnostic.ERROR
253                                || diagnosticSeverity == Diagnostic.CANCEL) {
254                        return IStatus.ERROR;
255                }
256                return IStatus.INFO;
257        }
258 
259        /**
260         * @generated
261         */
262        private static Set collectTargetElements(IStatus status,
263                        Set targetElementCollector, List allConstraintStatuses) {
264                if (status instanceof IConstraintStatus) {
265                        targetElementCollector
266                                        .add(((IConstraintStatus) status).getTarget());
267                        allConstraintStatuses.add(status);
268                }
269                if (status.isMultiStatus()) {
270                        IStatus[] children = status.getChildren();
271                        for (int i = 0; i < children.length; i++) {
272                                collectTargetElements(children[i], targetElementCollector,
273                                                allConstraintStatuses);
274                        }
275                }
276                return targetElementCollector;
277        }
278 
279        /**
280         * @generated
281         */
282        private static Set collectTargetElements(Diagnostic diagnostic,
283                        Set targetElementCollector, List allDiagnostics) {
284                List data = diagnostic.getData();
285                EObject target = null;
286                if (data != null && !data.isEmpty() && data.get(0) instanceof EObject) {
287                        target = (EObject) data.get(0);
288                        targetElementCollector.add(target);
289                        allDiagnostics.add(diagnostic);
290                }
291                if (diagnostic.getChildren() != null
292                                && !diagnostic.getChildren().isEmpty()) {
293                        for (Iterator it = diagnostic.getChildren().iterator(); it
294                                        .hasNext();) {
295                                collectTargetElements((Diagnostic) it.next(),
296                                                targetElementCollector, allDiagnostics);
297                        }
298                }
299                return targetElementCollector;
300        }
301}

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