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

COVERAGE SUMMARY FOR SOURCE FILE [VariableUsageEditHelperAdvice.java]

nameclass, %method, %block, %line, %
VariableUsageEditHelperAdvice.java0%   (0/1)0%   (0/13)0%   (0/763)0%   (0/245)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class VariableUsageEditHelperAdvice0%   (0/1)0%   (0/13)0%   (0/763)0%   (0/245)
VariableUsageEditHelperAdvice (): void 0%   (0/1)0%   (0/3)0%   (0/1)
caseEmitEventActionInputParameter (ConfigureRequest): ICommand 0%   (0/1)0%   (0/144)0%   (0/46)
caseExternalCallActionInputParameter (ConfigureRequest): ICommand 0%   (0/1)0%   (0/119)0%   (0/38)
caseExternalCallActionOutputParameter (ConfigureRequest): ICommand 0%   (0/1)0%   (0/36)0%   (0/12)
caseInfrastructureCallParameter (ConfigureRequest): ICommand 0%   (0/1)0%   (0/123)0%   (0/38)
caseSetVariableAction (ConfigureRequest): ICommand 0%   (0/1)0%   (0/114)0%   (0/35)
getAfterConfigureCommand (ConfigureRequest): ICommand 0%   (0/1)0%   (0/62)0%   (0/15)
getCall (EObject): ExternalCallAction 0%   (0/1)0%   (0/17)0%   (0/6)
getEmitEventAction (EObject): EmitEventAction 0%   (0/1)0%   (0/17)0%   (0/6)
getInternalAction (EObject): InternalAction 0%   (0/1)0%   (0/17)0%   (0/6)
getMyService (EObject): Signature 0%   (0/1)0%   (0/15)0%   (0/4)
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.seff.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.swt.SWT;
21import org.eclipse.swt.widgets.MessageBox;
22import org.eclipse.swt.widgets.Shell;
23import org.eclipse.ui.PlatformUI;
24 
25import de.uka.ipd.sdq.pcm.dialogs.datatype.DataTypeContainer;
26import de.uka.ipd.sdq.pcm.dialogs.datatype.InnerDeclarationContainer;
27import de.uka.ipd.sdq.pcm.dialogs.selection.PalladioSelectEObjectDialog;
28import de.uka.ipd.sdq.pcm.dialogs.variablenames.SetOutputVariableNameDialog;
29import de.uka.ipd.sdq.pcm.dialogs.variableusage.VariableUsageInputParameterContentProvider;
30import de.uka.ipd.sdq.pcm.dialogs.variableusage.VariableUsageItemProviderAdapterFactory;
31import de.uka.ipd.sdq.pcm.dialogs.variableusage.VariableUsageOutputParameterContentProvider;
32import de.uka.ipd.sdq.pcm.gmf.seff.providers.PalladioComponentModelElementTypes;
33import de.uka.ipd.sdq.pcm.parameter.ParameterPackage;
34import de.uka.ipd.sdq.pcm.repository.InfrastructureInterface;
35import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature;
36import de.uka.ipd.sdq.pcm.repository.InnerDeclaration;
37import de.uka.ipd.sdq.pcm.repository.Parameter;
38import de.uka.ipd.sdq.pcm.repository.Repository;
39import de.uka.ipd.sdq.pcm.repository.Signature;
40import de.uka.ipd.sdq.pcm.repository.provider.RepositoryItemProviderAdapterFactory;
41import de.uka.ipd.sdq.pcm.seff.EmitEventAction;
42import de.uka.ipd.sdq.pcm.seff.ExternalCallAction;
43import de.uka.ipd.sdq.pcm.seff.InternalAction;
44import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF;
45import de.uka.ipd.sdq.pcm.seff.SetVariableAction;
46import de.uka.ipd.sdq.pcm.seff.seff_performance.InfrastructureCall;
47import de.uka.ipd.sdq.pcmbench.ui.provider.PalladioItemProviderAdapterFactory;
48import de.uka.ipd.sdq.stoex.AbstractNamedReference;
49import de.uka.ipd.sdq.stoex.NamespaceReference;
50import de.uka.ipd.sdq.stoex.StoexFactory;
51 
52 
53/**
54 * FIXME: Everything seems not generated. If that's the case add "@generated NOT" to the methods.
55 */
56 
57/**
58 * @author admin
59 * 
60 */
61public class VariableUsageEditHelperAdvice extends AbstractEditHelperAdvice
62                implements IEditHelperAdvice {
63 
64        /*
65         * (non-Javadoc)
66         * 
67         * @see org.eclipse.gmf.runtime.emf.type.core.edithelper.AbstractEditHelperAdvice#getAfterConfigureCommand(org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest)
68         */
69        @Override
70        protected ICommand getAfterConfigureCommand(ConfigureRequest request) {
71                if (request.getElementToConfigure().eContainer() instanceof ExternalCallAction 
72                                || request.getElementToConfigure().eContainer() instanceof EmitEventAction 
73                                || request.getElementToConfigure().eContainer() instanceof InfrastructureCall) {
74                        // FIXME: To check the correct IDs
75                        if (request.getTypeToConfigure() == PalladioComponentModelElementTypes.VariableUsage_3042){
76                                // VariableUsage for input variables (ExternalCallAction)
77                                return caseExternalCallActionInputParameter(request);
78                        } else if (request.getTypeToConfigure() == PalladioComponentModelElementTypes.VariableUsage_3049){
79                                // VariableUsage for output variables (ExternalCallAction)
80                                return caseExternalCallActionOutputParameter(request);
81                        } else if (request.getTypeToConfigure() == PalladioComponentModelElementTypes.VariableUsage_3047){
82                                // VariableUsage for input variables (EmitEventActionAction)
83                                return caseEmitEventActionInputParameter(request);
84                        } else if (request.getTypeToConfigure() == PalladioComponentModelElementTypes.VariableUsage_3054) {
85                                // VariableUsage for (input) parameters (InfrastructureCall)
86                                return caseInfrastructureCallParameter(request);
87                        } else {
88                                return null;
89                        }
90                } else if (request.getElementToConfigure().eContainer() instanceof SetVariableAction) {
91                        return caseSetVariableAction(request);
92                } else
93                        return new CanceledCommand();
94        }
95 
96        private ICommand caseExternalCallActionOutputParameter(
97                        ConfigureRequest request) {
98 
99                SetOutputVariableNameDialog dialog = new SetOutputVariableNameDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
100                dialog.open();
101                
102                String enteredName = dialog.getResult();
103                if (enteredName == null){
104                        return new CanceledCommand();
105                }
106                
107                AbstractNamedReference namedReference = 
108                        dialog.getOutputVariableReference();
109 
110                ICommand cmd = new SetValueCommand(new SetRequest(request
111                                .getElementToConfigure(), ParameterPackage.eINSTANCE
112                                .getVariableUsage_NamedReference__VariableUsage(),
113                                namedReference));
114                return cmd;
115        }
116 
117 
118        private ICommand caseSetVariableAction(ConfigureRequest request) {
119                ArrayList<Object> filterList = new ArrayList<Object>();
120                filterList.add(Repository.class);
121                filterList.add(Signature.class);
122 
123                ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
124                PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(
125                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
126                                filterList, additionalReferences, this.getMyService(request.getElementToConfigure()));
127                /**
128                 * set a ContentProvider for dialog TreeViewer
129                 */
130                dialog.setViewerContentProvider(new VariableUsageOutputParameterContentProvider());
131                ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory();
132                adapterFactory
133                                .addAdapterFactory(new ResourceItemProviderAdapterFactory());
134                adapterFactory
135                                .addAdapterFactory(new RepositoryItemProviderAdapterFactory());
136                adapterFactory
137                                .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
138                /**
139                 * set a LabelProvider for dialog TreeViewer
140                 */
141                dialog
142                                .setViewerLabelProvider(new AdapterFactoryLabelProvider(
143                                                new VariableUsageItemProviderAdapterFactory(
144                                                                new PalladioItemProviderAdapterFactory(
145                                                                                adapterFactory))));
146                dialog.open();
147 
148                if (dialog.getResult() == null)
149                        return new CanceledCommand();
150                if (!(dialog.getResult() instanceof DataTypeContainer)
151                                && !(dialog.getResult() instanceof InnerDeclarationContainer)
152                                && !(dialog.getResult() instanceof Parameter))
153                        return new CanceledCommand();
154 
155                EObject resource = (EObject) dialog.getResult();
156 
157                AbstractNamedReference namedReference = setNamedReference(resource,
158                                null, true);
159 
160                ICommand cmd = new SetValueCommand(new SetRequest(request
161                                .getElementToConfigure(), ParameterPackage.eINSTANCE
162                                .getVariableUsage_NamedReference__VariableUsage(),
163                                namedReference));
164                return cmd;
165        }
166 
167        private Signature getMyService(EObject elementToConfigure) {
168                EObject current = elementToConfigure;
169                while (current != null && !(current instanceof ResourceDemandingSEFF))
170                        current = current.eContainer();
171                return ((ResourceDemandingSEFF)current).getDescribedService__SEFF();
172        }
173 
174        private ICommand caseExternalCallActionInputParameter(
175                        ConfigureRequest request) {
176                EObject resource = null;
177                ExternalCallAction call = getCall(request.getElementToConfigure());
178 
179                ArrayList<Object> filterList = new ArrayList<Object>();
180                filterList.add(Repository.class);
181                filterList.add(Signature.class);
182 
183                ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
184                PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(
185                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
186                                filterList, additionalReferences, call
187                                                .getCalledService_ExternalService());
188                /**
189                 * set a ContentProvider for dialog TreeViewer
190                 */
191                dialog.setViewerContentProvider(new VariableUsageInputParameterContentProvider());
192                ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory();
193                adapterFactory
194                                .addAdapterFactory(new ResourceItemProviderAdapterFactory());
195                adapterFactory
196                                .addAdapterFactory(new RepositoryItemProviderAdapterFactory());
197                adapterFactory
198                                .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
199                /**
200                 * set a LabelProvider for dialog TreeViewer
201                 */
202                dialog
203                                .setViewerLabelProvider(new AdapterFactoryLabelProvider(
204                                                new VariableUsageItemProviderAdapterFactory(
205                                                                new PalladioItemProviderAdapterFactory(
206                                                                                adapterFactory))));
207                dialog.open();
208 
209                if (dialog.getResult() == null)
210                        return new CanceledCommand();
211                if (!(dialog.getResult() instanceof DataTypeContainer)
212                                && !(dialog.getResult() instanceof InnerDeclarationContainer)
213                                && !(dialog.getResult() instanceof Parameter))
214                        return new CanceledCommand();
215 
216                resource = (EObject) dialog.getResult();
217 
218                AbstractNamedReference namedReference = setNamedReference(resource,
219                                null, true);
220 
221                ICommand cmd = new SetValueCommand(new SetRequest(request
222                                .getElementToConfigure(), ParameterPackage.eINSTANCE
223                                .getVariableUsage_NamedReference__VariableUsage(),
224                                namedReference));
225                return cmd;
226        }
227 
228        /**
229         * Handle command about an input variable usage for an EmitEventAction.
230         * @param request The configuration request
231         * @return The ICommand for further processing
232         */
233        private ICommand caseEmitEventActionInputParameter(
234                        ConfigureRequest request) {
235                EObject resource = null;
236                EmitEventAction action = getEmitEventAction(request.getElementToConfigure());
237                Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
238                if (action.getEventType__EmitEventAction().getParameter__EventType()==null) {
239                        
240 
241                        MessageBox messageBox =
242                                new MessageBox(shell ,
243                                                SWT.OK
244                                                | SWT.ICON_ERROR);
245                        messageBox.setText("Notice");
246                        messageBox.setMessage("The Type of the event is not set. You must define the data"
247                                        +"type of the event in the repository first.");
248                        messageBox.open();
249 
250                        return new CanceledCommand();
251                        
252                }
253                
254                ArrayList<Object> filterList = new ArrayList<Object>();
255                filterList.add(Repository.class);
256                filterList.add(Signature.class);
257 
258                ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
259                PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(
260                                shell, filterList, additionalReferences, action
261                                                .getEventType__EmitEventAction());
262                /**
263                 * set a ContentProvider for dialog TreeViewer
264                 */
265                dialog.setViewerContentProvider(new VariableUsageInputParameterContentProvider());
266                ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory();
267                adapterFactory
268                                .addAdapterFactory(new ResourceItemProviderAdapterFactory());
269                adapterFactory
270                                .addAdapterFactory(new RepositoryItemProviderAdapterFactory());
271                adapterFactory
272                                .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
273                /**
274                 * set a LabelProvider for dialog TreeViewer
275                 */
276                dialog
277                                .setViewerLabelProvider(new AdapterFactoryLabelProvider(
278                                                new VariableUsageItemProviderAdapterFactory(
279                                                                new PalladioItemProviderAdapterFactory(
280                                                                                adapterFactory))));
281                dialog.open();
282 
283                if (dialog.getResult() == null)
284                        return new CanceledCommand();
285                if (!(dialog.getResult() instanceof DataTypeContainer)
286                                && !(dialog.getResult() instanceof InnerDeclarationContainer)
287                                && !(dialog.getResult() instanceof Parameter))
288                        return new CanceledCommand();
289 
290                resource = (EObject) dialog.getResult();
291 
292                AbstractNamedReference namedReference = setNamedReference(resource,
293                                null, true);
294 
295                ICommand cmd = new SetValueCommand(new SetRequest(request
296                                .getElementToConfigure(), ParameterPackage.eINSTANCE
297                                .getVariableUsage_NamedReference__VariableUsage(),
298                                namedReference));
299                return cmd;
300        }
301 
302        /**
303         * Handle command about an variable usage for an InfrastructureCall.
304         * @param request The configuration request
305         * @return The ICommand for further processing
306         */
307        private ICommand caseInfrastructureCallParameter(
308                        ConfigureRequest request) {
309                EObject resource = null;
310                InfrastructureCall call = (InfrastructureCall) request.getElementToConfigure().eContainer();
311                
312                ArrayList<Object> filterList = new ArrayList<Object>();
313                filterList.add(Repository.class);
314                filterList.add(InfrastructureInterface.class);
315                filterList.add(InfrastructureSignature.class);
316 
317                ArrayList<EReference> additionalReferences = new ArrayList<EReference>();
318                PalladioSelectEObjectDialog dialog = new PalladioSelectEObjectDialog(
319                                PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(),
320                                filterList, additionalReferences, call.getSignature__InfrastructureCall()
321                                                );
322                /**
323                 * set a ContentProvider for dialog TreeViewer
324                 */
325                dialog.setViewerContentProvider(new VariableUsageInputParameterContentProvider());
326                ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory();
327                adapterFactory
328                                .addAdapterFactory(new ResourceItemProviderAdapterFactory());
329                adapterFactory
330                                .addAdapterFactory(new RepositoryItemProviderAdapterFactory());
331                adapterFactory
332                                .addAdapterFactory(new ReflectiveItemProviderAdapterFactory());
333                /**
334                 * set a LabelProvider for dialog TreeViewer
335                 */
336                dialog
337                                .setViewerLabelProvider(new AdapterFactoryLabelProvider(
338                                                new VariableUsageItemProviderAdapterFactory(
339                                                                new PalladioItemProviderAdapterFactory(
340                                                                                adapterFactory))));
341                dialog.open();
342 
343                if (dialog.getResult() == null)
344                        return new CanceledCommand();
345                if (!(dialog.getResult() instanceof DataTypeContainer)
346                                && !(dialog.getResult() instanceof InnerDeclarationContainer)
347                                && !(dialog.getResult() instanceof Parameter))
348                        return new CanceledCommand();
349 
350                resource = (EObject) dialog.getResult();
351 
352                AbstractNamedReference namedReference = setNamedReference(resource,
353                                null, true);
354 
355                ICommand cmd = new SetValueCommand(new SetRequest(request
356                                .getElementToConfigure(), ParameterPackage.eINSTANCE
357                                .getVariableUsage_NamedReference__VariableUsage(),
358                                namedReference));
359                return cmd;
360        }
361        
362        /**
363         * @return - String: specification of VariableCharacterisation
364         */
365        private AbstractNamedReference setNamedReference(EObject object,
366                        AbstractNamedReference namedReference, boolean last) {
367                /**
368                 * Parameter
369                 */
370                if (object instanceof Parameter) {
371                        Parameter parameter = (Parameter) object;
372                        AbstractNamedReference parameterReference = referenceFactory(
373                                        parameter.getParameterName(), last);
374                        if (!last) {
375                                ((NamespaceReference) parameterReference)
376                                                .setInnerReference_NamespaceReference(namedReference);
377                        }
378                        return parameterReference;
379                }
380 
381                /**
382                 * TreeType container for CollectionDataType
383                 * 
384                 * @see de.uka.ipd.sdq.pcm.gmf.seff.helper.VariableUsageContentProvider.TreeType
385                 */
386                if (object instanceof DataTypeContainer) {
387                        DataTypeContainer treeType = (DataTypeContainer) object;
388                        if (treeType.getParent() != null) {
389                                AbstractNamedReference treetypeReference = referenceFactory(
390                                                "INNER", last);
391                                if (!last) {
392                                        ((NamespaceReference) treetypeReference)
393                                                        .setInnerReference_NamespaceReference(namedReference);
394                                }
395                                return setNamedReference((EObject) treeType.getParent(),
396                                                treetypeReference, false);
397                        }
398                }
399 
400                /**
401                 * TreeDeclaration container for InnerDeclaration
402                 * 
403                 * @see de.uka.ipd.sdq.pcm.gmf.seff.helper.VariableUsageContentProvider.TreeDeclaration
404                 */
405                if (object instanceof InnerDeclarationContainer) {
406                        InnerDeclarationContainer treeDeclaration = (InnerDeclarationContainer) object;
407                        InnerDeclaration declaration = (InnerDeclaration) treeDeclaration
408                                        .getObject();
409 
410                        AbstractNamedReference declarationReference = referenceFactory(
411                                        declaration.getEntityName(), last);
412                        if (!last) {
413                                ((NamespaceReference) declarationReference)
414                                                .setInnerReference_NamespaceReference(namedReference);
415                        }
416                        return setNamedReference((EObject) treeDeclaration.getParent(),
417                                        declarationReference, false);
418                }
419 
420                return namedReference;
421        }
422 
423        /**
424         * Get the ExternalCallAction out of a request object.
425         * The request object is recursively scanned for the action while it might have been wrapped.
426         * 
427         * @param object The ECore object to scan
428         * @return The ExternalCallAction or null if no ExternalCallAction has been contained
429         */
430        private ExternalCallAction getCall(EObject object) {
431                EObject container = object;
432                while (!(container instanceof ExternalCallAction))
433                        container = container.eContainer();
434                if (!(container instanceof ExternalCallAction))
435                        return null;
436                return (ExternalCallAction) container;
437        }
438 
439        /**
440         * Get the EmitEventAction out of a request object.
441         * The request object is recursively scanned for the action while it might have been wrapped.
442         * 
443         * @param object The ECore object to scan
444         * @return The EmitEventAction or null if no EmitEventAction has been contained
445         */
446        private EmitEventAction getEmitEventAction(EObject object) {
447                EObject container = object;
448                while (!(container instanceof EmitEventAction))
449                        container = container.eContainer();
450                if (!(container instanceof EmitEventAction))
451                        return null;
452                return (EmitEventAction) container;
453        }
454 
455        /**
456         * Get the InternalAction out of a request object.
457         * The request object is recursively scanned for the action while it might have been wrapped.
458         * 
459         * @param object The ECore object to scan.
460         * @return The InternalAction or null if no InternalAction has been contained.
461         */
462        private InternalAction getInternalAction(EObject object) {
463                EObject container = object;
464                while (!(container instanceof InternalAction))
465                        container = container.eContainer();
466                if (!(container instanceof InternalAction))
467                        return null;
468                return (InternalAction) container;
469        }
470        
471        /**
472         * Create the AbstractNamedReference and set a string parameter
473         */
474        private AbstractNamedReference referenceFactory(String string,
475                        boolean shouldGenerateVariableReference) {
476                AbstractNamedReference parameterReference = null;
477                if (shouldGenerateVariableReference) {
478                        parameterReference = StoexFactory.eINSTANCE
479                                        .createVariableReference();
480                } else {
481                        parameterReference = StoexFactory.eINSTANCE
482                                        .createNamespaceReference();
483                }
484                parameterReference.setReferenceName(string);
485                return parameterReference;
486        }
487}

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