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

COVERAGE SUMMARY FOR SOURCE FILE [SetLatencyThroughputAndLanTypeCommand.java]

nameclass, %method, %block, %line, %
SetLatencyThroughputAndLanTypeCommand.java0%   (0/1)0%   (0/4)0%   (0/146)0%   (0/42)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class SetLatencyThroughputAndLanTypeCommand0%   (0/1)0%   (0/4)0%   (0/146)0%   (0/42)
SetLatencyThroughputAndLanTypeCommand (ConfigureRequest): void 0%   (0/1)0%   (0/10)0%   (0/4)
doExecuteWithResult (IProgressMonitor, IAdaptable): CommandResult 0%   (0/1)0%   (0/38)0%   (0/13)
getLanType (): CommunicationLinkResourceType 0%   (0/1)0%   (0/65)0%   (0/15)
getRandomVariableFromStoExDialog (String): PCMRandomVariable 0%   (0/1)0%   (0/33)0%   (0/10)

1package de.uka.ipd.sdq.pcm.gmf.resource.helper;
2 
3import java.util.ArrayList;
4import java.util.Collection;
5 
6import org.eclipse.core.commands.ExecutionException;
7import org.eclipse.core.runtime.IAdaptable;
8import org.eclipse.core.runtime.IProgressMonitor;
9import org.eclipse.emf.common.util.EList;
10import org.eclipse.emf.ecore.EObject;
11import org.eclipse.emf.ecore.resource.Resource;
12import org.eclipse.emf.edit.domain.EditingDomain;
13import org.eclipse.emf.query.conditions.eobjects.structuralfeatures.EObjectAttributeValueCondition;
14import org.eclipse.emf.query.statements.FROM;
15import org.eclipse.emf.query.statements.IQueryResult;
16import org.eclipse.emf.query.statements.SELECT;
17import org.eclipse.emf.query.statements.WHERE;
18import org.eclipse.emf.transaction.util.TransactionUtil;
19import org.eclipse.gmf.runtime.common.core.command.CommandResult;
20import org.eclipse.gmf.runtime.emf.type.core.commands.ConfigureElementCommand;
21import org.eclipse.gmf.runtime.emf.type.core.requests.ConfigureRequest;
22import org.eclipse.jface.dialogs.Dialog;
23import org.eclipse.ui.PlatformUI;
24 
25import de.uka.ipd.sdq.pcm.core.CoreFactory;
26import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
27import de.uka.ipd.sdq.pcm.dialogs.stoex.StochasticExpressionEditDialog;
28import de.uka.ipd.sdq.pcm.resourceenvironment.CommunicationLinkResourceSpecification;
29import de.uka.ipd.sdq.pcm.resourceenvironment.LinkingResource;
30import de.uka.ipd.sdq.pcm.resourcetype.CommunicationLinkResourceType;
31import de.uka.ipd.sdq.pcm.resourcetype.ResourcetypePackage;
32import de.uka.ipd.sdq.stoex.analyser.visitors.TypeEnum;
33 
34public class SetLatencyThroughputAndLanTypeCommand extends ConfigureElementCommand {
35        
36        private static final String LATENCY_DISPLAY_TITLE = "Set Latency";
37        private static final String THROUGHPUT_DISPLAY_TITLE = "Set Throughput";
38        private ConfigureRequest request = null;
39        
40        // id of LAN in PCM resource repository
41        private static final String LAN_COMMUNICATION_LINK_RESOURCE_TYPE = "_o3sScH2AEdyH8uerKnHYug";
42 
43        public SetLatencyThroughputAndLanTypeCommand(ConfigureRequest request) {
44                super(request);
45                this.request = request;
46        }
47 
48        /**
49         * Method opens latency and throughput StoEx-dialogs and sets attributes of
50         * Communication Link Resource Specification accordingly
51         */
52        @Override
53        protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
54                // get Linking Resource and Communication Link Resource Specification
55                LinkingResource linkingResource = (LinkingResource) request.getElementToConfigure();
56                // this containment was set before by AddCommunicationLinkResourceSpecificationEditHelperAdvice.getBeforeConfigureCommand()
57                CommunicationLinkResourceSpecification communicationLinkResourceSpecification = linkingResource.getCommunicationLinkResourceSpecifications_LinkingResource();
58                
59                PCMRandomVariable latency = getRandomVariableFromStoExDialog(LATENCY_DISPLAY_TITLE);
60                if (latency == null) {
61                        return CommandResult.newCancelledCommandResult();
62                }
63                communicationLinkResourceSpecification.setLatency_CommunicationLinkResourceSpecification(latency);
64                
65                PCMRandomVariable throughput = getRandomVariableFromStoExDialog(THROUGHPUT_DISPLAY_TITLE);
66                if (throughput == null) {
67                        return CommandResult.newCancelledCommandResult();
68                }
69                communicationLinkResourceSpecification.setThroughput_CommunicationLinkResourceSpecification(throughput);
70                
71                CommunicationLinkResourceType lanType = getLanType();
72                communicationLinkResourceSpecification.setCommunicationLinkResourceType_CommunicationLinkResourceSpecification(lanType);
73                
74                return CommandResult.newOKCommandResult();
75        }
76        
77        /**
78         * @return LAN type from resource repository
79         */
80        private CommunicationLinkResourceType getLanType() {
81                EObject requestElement = (EObject) request.getElementsToEdit().get(0);
82                EditingDomain editingDomain = TransactionUtil.getEditingDomain(requestElement);                 
83                EList<Resource> resources = editingDomain.getResourceSet().getResources();
84                Collection<EObject> c = new ArrayList<EObject>();                
85                for(Resource r : resources) {                        
86                        c.addAll(r.getContents());                        
87                }
88                SELECT statement = new SELECT(
89                new FROM(c),
90                new WHERE(
91                                new EObjectAttributeValueCondition(
92                                                ResourcetypePackage.eINSTANCE.getCommunicationLinkResourceType().getEIDAttribute(),
93                                                new org.eclipse.emf.query.conditions.strings.StringValue(LAN_COMMUNICATION_LINK_RESOURCE_TYPE) 
94                                ))                        
95                );
96                IQueryResult queryResult = statement.execute();
97                CommunicationLinkResourceType lanType = (CommunicationLinkResourceType)queryResult.iterator().next();
98                return lanType;
99        }
100        
101        /**
102         * Opens a StoxEx dialog and returns the resulting {@link PCMRandomVariable}
103         * @param displayTitle Title of the StoEx dialog
104         * @return PCMRandomVariable if user entered valid data and confirmed. Will
105         * return null if user canceled dialog
106         */
107        private PCMRandomVariable getRandomVariableFromStoExDialog(String displayTitle) {
108                PCMRandomVariable randomVariable = CoreFactory.eINSTANCE.createPCMRandomVariable();
109                randomVariable.setSpecification("");
110 
111                StochasticExpressionEditDialog dialog = new StochasticExpressionEditDialog(PlatformUI.getWorkbench()
112                                .getActiveWorkbenchWindow().getShell(), TypeEnum.DOUBLE, randomVariable);
113                dialog.setDisplayTitle(displayTitle);
114                dialog.open();
115 
116                if (dialog.getReturnCode() == Dialog.CANCEL) {
117                        return null;
118                }        
119                
120                randomVariable.setSpecification(dialog.getResultText());
121                return randomVariable;
122        }
123 
124}

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