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

COVERAGE SUMMARY FOR SOURCE FILE [VariableUsageEditHelperAdvice.java]

nameclass, %method, %block, %line, %
VariableUsageEditHelperAdvice.java0%   (0/1)0%   (0/5)0%   (0/235)0%   (0/83)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VariableUsageEditHelperAdvice0%   (0/1)0%   (0/5)0%   (0/235)0%   (0/83)
VariableUsageEditHelperAdvice (): void 0%   (0/1)0%   (0/3)0%   (0/1)
getAfterConfigureCommand (ConfigureRequest): ICommand 0%   (0/1)0%   (0/119)0%   (0/38)
getCall (EObject): EntryLevelSystemCall 0%   (0/1)0%   (0/17)0%   (0/6)
referenceFactory (String, boolean): AbstractNamedReference 0%   (0/1)0%   (0/16)0%   (0/8)
setNamedReference (EObject, AbstractNamedReference, boolean): AbstractNamedRe... 0%   (0/1)0%   (0/80)0%   (0/30)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.pcm.gmf.usage.helper;
5 
6import java.util.ArrayList;
7 
8import org.eclipse.emf.ecore.EObject;
9import org.eclipse.emf.ecore.EReference;
10import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
11import org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory;
12import org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory;
13import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
14import org.eclipse.gmf.runtime.common.core.command.ICommand;
15import org.eclipse.gmf.runtime.emf.type.core.commands.SetValueCommand;
16import org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice;
17import org.eclipse.gmf.runtime.emf.type.core.edithelper.IEditHelperAdvice;
18import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
19import org.eclipse.gmf.runtime.emf.type.core.requests.SetRequest;
20import org.eclipse.ui.PlatformUI;
21 
22import de.uka.ipd.sdq.pcm.dialogs.datatype.DataTypeContainer;
23import de.uka.ipd.sdq.pcm.dialogs.datatype.InnerDeclarationContainer;
24import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog;
25import de.uka.ipd.sdq.pcm.dialogs.variableusage.VariableUsageInputParameterContentProvider;
26import de.uka.ipd.sdq.pcm.dialogs.variableusage.VariableUsageItemProviderAdapterFactory;
27import de.uka.ipd.sdq.pcm.parameter.ParameterPackage;
28import de.uka.ipd.sdq.pcm.repository.InnerDeclaration;
29import de.uka.ipd.sdq.pcm.repository.Parameter;
30import de.uka.ipd.sdq.pcm.repository.Repository;
31import de.uka.ipd.sdq.pcm.repository.Signature;
32import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory;
33import de.uka.ipd.sdq.pcm.usagemodel.EntryLevelSystemCall;
34import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory;
35import de.uka.ipd.sdq.stoex.AbstractNamedReference;
36import de.uka.ipd.sdq.stoex.NamespaceReference;
37import de.uka.ipd.sdq.stoex.StoexFactory;
38 
39/**
40 * @author admin
41 *
42 */
43public class VariableUsageEditHelperAdvice extends AbstractEditHelperAdvice
44                implements IEditHelperAdvice {
45 
46        /* (non-Javadoc)
47         * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest)
48         */
49        @Override
50        protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
51                EObject resource = null;
52                EntryLevelSystemCall systemCall = getCall(request.getElementToConfigure());
53 
54                ArrayList<Object> filterList = new ArrayList<Object>();
55                filterList.add(Repository.class);
56                filterList.add(Signature.class);
57 
58                ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
59                PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(
60                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
61                                filterList, 
62                                additionalReferences,
63                                systemCall.getOperationSignature__EntryLevelSystemCall());
64                /**
65                 * set a ContentProvider for dialog TreeViewer
66                 */
67                dialog.setViewerContentProvider(new VariableUsageInputParameterContentProvider());
68                ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory();
69                adapterFactory
70                                .addAdapterFactory(new ResourceItemProviderAdapterFactory());
71                adapterFactory
72                                .addAdapterFactory(new RepositoryItemProviderAdapterFactory());
73                adapterFactory
74                                .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
75                /**
76                 * set a LabelProvider for dialog TreeViewer
77                 */
78                dialog
79                                .setViewerLabelProvider(new AdapterFactoryLabelProvider(
80                                                new VariableUsageItemProviderAdapterFactory(
81                                                                new PalladioItemProviderAdapterFactory(
82                                                                                adapterFactory))));
83                dialog.open();
84                
85                if (dialog.getResult() == null)
86                        return new CanceledCommand();
87                if (!(dialog.getResult() instanceof DataTypeContainer)
88                                && !(dialog.getResult() instanceof InnerDeclarationContainer)
89                                   && !(dialog.getResult() instanceof Parameter))
90                        return new CanceledCommand();
91        
92                resource = (EObject) dialog.getResult();
93                
94                AbstractNamedReference namedReference = setNamedReference(resource, null, true);
95 
96                ICommand cmd = new SetValueCommand(new SetRequest(request
97                                .getElementToConfigure(), ParameterPackage.eINSTANCE
98                                .getVariableUsage_NamedReference__VariableUsage(),
99                                namedReference));
100                return cmd;
101        }
102 
103        /**
104         * @return - String: specification of VariableCharacterisation
105         */
106        private AbstractNamedReference setNamedReference(EObject object,
107                        AbstractNamedReference namedReference, boolean last) {
108                /**
109                 * Parameter
110                 */
111                if (object instanceof Parameter) {
112                        Parameter parameter = (Parameter) object;
113                        AbstractNamedReference parameterReference = referenceFactory(
114                                        parameter.getParameterName(), last);
115                        if (!last) {
116                                ((NamespaceReference) parameterReference)
117                                                .setInnerReference_NamespaceReference(namedReference);
118                        }
119                        return parameterReference;
120                }
121 
122                /**
123                 * TreeType container for CollectionDataType
124                 * 
125                 * @see de.uka.ipd.sdq.pcm.gmf.seff.helper.VariableUsageContentProvider.TreeType
126                 */
127                if (object instanceof DataTypeContainer) {
128                        DataTypeContainer treeType = (DataTypeContainer) object;
129                        if (treeType.getParent() != null) {
130                                AbstractNamedReference treetypeReference = referenceFactory(
131                                                "INNER", last);
132                                if (!last) {
133                                        ((NamespaceReference) treetypeReference)
134                                                        .setInnerReference_NamespaceReference(namedReference);
135                                }
136                                return setNamedReference((EObject) treeType.getParent(),
137                                                treetypeReference, false);
138                        }
139                }
140 
141                /**
142                 * TreeDeclaration container for InnerDeclaration
143                 * 
144                 * @see de.uka.ipd.sdq.pcm.gmf.seff.helper.VariableUsageContentProvider.TreeDeclaration
145                 */
146                if (object instanceof InnerDeclarationContainer) {
147                        InnerDeclarationContainer treeDeclaration = (InnerDeclarationContainer) object;
148                        InnerDeclaration declaration = (InnerDeclaration) treeDeclaration
149                                        .getObject();
150 
151                        AbstractNamedReference declarationReference = referenceFactory(
152                                        declaration.getEntityName(), last);
153                        if (!last) {
154                                ((NamespaceReference) declarationReference)
155                                                .setInnerReference_NamespaceReference(namedReference);
156                        }
157                        return setNamedReference((EObject) treeDeclaration.getParent(),
158                                        declarationReference, false);
159                }
160 
161                return namedReference;
162        }
163 
164        /**
165         * Create the AbstractNamedReference and set a string parameter
166         */
167        private AbstractNamedReference referenceFactory(String string,
168                        boolean shouldGenerateVariableReference) {
169                AbstractNamedReference parameterReference = null;
170                if (shouldGenerateVariableReference) {
171                        parameterReference = StoexFactory.eINSTANCE
172                                        .createVariableReference();
173                } else {
174                        parameterReference = StoexFactory.eINSTANCE
175                                        .createNamespaceReference();
176                }
177                parameterReference.setReferenceName(string);
178                return parameterReference;
179        }
180 
181        private EntryLevelSystemCall getCall(EObject a) {
182                EObject container = a;
183                while (!(container instanceof EntryLevelSystemCall))
184                        container = container.eContainer();
185                if (!(container instanceof EntryLevelSystemCall))
186                        return null;
187                return (EntryLevelSystemCall) container;
188        }
189}

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