1 | /* |
2 | * Copyright 2007, SDQ, IPD, University of Karlsruhe |
3 | */ |
4 | package de.uka.ipd.sdq.pcm.gmf.usage.providers; |
5 | |
6 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
7 | import org.eclipse.gmf.runtime.notation.View; |
8 | |
9 | import de.uka.ipd.sdq.pcm.gmf.usage.edit.parts.UsageScenarioEditPart; |
10 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelUsageDiagramEditorPlugin; |
11 | import de.uka.ipd.sdq.pcm.gmf.usage.part.PalladioComponentModelVisualIDRegistry; |
12 | |
13 | /** |
14 | * @generated |
15 | */ |
16 | public class PalladioComponentModelValidationProvider { |
17 | |
18 | /** |
19 | * @generated |
20 | */ |
21 | private static boolean constraintsActive = false; |
22 | |
23 | /** |
24 | * @generated |
25 | */ |
26 | public static boolean shouldConstraintsBePrivate() { |
27 | return false; |
28 | } |
29 | |
30 | /** |
31 | * @generated |
32 | */ |
33 | public static void runWithConstraints( |
34 | TransactionalEditingDomain editingDomain, Runnable operation) { |
35 | final Runnable op = operation; |
36 | Runnable task = new Runnable() { |
37 | public void run() { |
38 | try { |
39 | constraintsActive = true; |
40 | op.run(); |
41 | } finally { |
42 | constraintsActive = false; |
43 | } |
44 | } |
45 | }; |
46 | if (editingDomain != null) { |
47 | try { |
48 | editingDomain.runExclusive(task); |
49 | } catch (Exception e) { |
50 | PalladioComponentModelUsageDiagramEditorPlugin.getInstance() |
51 | .logError("Validation failed", e); //$NON-NLS-1$ |
52 | } |
53 | } else { |
54 | task.run(); |
55 | } |
56 | } |
57 | |
58 | /** |
59 | * @generated |
60 | */ |
61 | static boolean isInDefaultEditorContext(Object object) { |
62 | if (shouldConstraintsBePrivate() && !constraintsActive) { |
63 | return false; |
64 | } |
65 | if (object instanceof View) { |
66 | return constraintsActive |
67 | && UsageScenarioEditPart.MODEL_ID |
68 | .equals(PalladioComponentModelVisualIDRegistry |
69 | .getModelID((View) object)); |
70 | } |
71 | return true; |
72 | } |
73 | |
74 | } //PalladioComponentModelValidationProvider |