EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.pcmbench.ui.provider]

COVERAGE SUMMARY FOR SOURCE FILE [PalladioItemProvider.java]

nameclass, %method, %block, %line, %
PalladioItemProvider.java0%   (0/1)0%   (0/11)0%   (0/506)0%   (0/85)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PalladioItemProvider0%   (0/1)0%   (0/11)0%   (0/506)0%   (0/85)
PalladioItemProvider (AdapterFactory): void 0%   (0/1)0%   (0/4)0%   (0/2)
createCommand (Object, EditingDomain, Class, CommandParameter): Command 0%   (0/1)0%   (0/30)0%   (0/11)
getCreateChildDescription (Object, Object, Object, Collection): String 0%   (0/1)0%   (0/9)0%   (0/1)
getCreateChildImage (Object, Object, Object, Collection): Object 0%   (0/1)0%   (0/9)0%   (0/1)
getCreateChildResult (Object): Collection 0%   (0/1)0%   (0/6)0%   (0/1)
getCreateChildText (Object, Object, Object, Collection): String 0%   (0/1)0%   (0/65)0%   (0/15)
getCreateChildToolTipText (Object, Object, Object, Collection): String 0%   (0/1)0%   (0/9)0%   (0/1)
getTarget (): Notifier 0%   (0/1)0%   (0/5)0%   (0/1)
getText (Object): String 0%   (0/1)0%   (0/301)0%   (0/40)
palladioConvention (String): String 0%   (0/1)0%   (0/62)0%   (0/10)
setTarget (Notifier): void 0%   (0/1)0%   (0/6)0%   (0/2)

1/**
2 * 
3 */
4package de.uka.ipd.sdq.pcmbench.ui.provider;
5 
6import java.util.Collection;
7 
8import org.eclipse.emf.common.command.Command;
9import org.eclipse.emf.common.notify.Adapter;
10import org.eclipse.emf.common.notify.AdapterFactory;
11import org.eclipse.emf.common.notify.Notifier;
12import org.eclipse.emf.ecore.EObject;
13import org.eclipse.emf.ecore.EReference;
14import org.eclipse.emf.edit.command.CommandParameter;
15import org.eclipse.emf.edit.command.CreateChildCommand;
16import org.eclipse.emf.edit.domain.EditingDomain;
17import org.eclipse.emf.edit.provider.IEditingDomainItemProvider;
18import org.eclipse.emf.edit.provider.IItemLabelProvider;
19import org.eclipse.emf.edit.provider.IItemPropertySource;
20import org.eclipse.emf.edit.provider.IStructuredItemContentProvider;
21import org.eclipse.emf.edit.provider.ITreeItemContentProvider;
22import org.eclipse.emf.edit.provider.ItemProviderDecorator;
23 
24import de.uka.ipd.sdq.identifier.Identifier;
25import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
26import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext;
27import de.uka.ipd.sdq.pcm.core.entity.Entity;
28import de.uka.ipd.sdq.pcm.resourceenvironment.ProcessingResourceSpecification;
29import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF;
30import de.uka.ipd.sdq.pcmbench.ui.PCMBenchUIPlugin;
31 
32/**
33 * @author Snowball
34 * Palladio Item Provider which renders Labels for elements of the Palladio Component Model
35 *
36 */
37public class PalladioItemProvider extends ItemProviderDecorator implements
38        IEditingDomainItemProvider,        
39        IStructuredItemContentProvider,        
40        ITreeItemContentProvider,        
41        IItemLabelProvider,        
42        IItemPropertySource,
43        Adapter,
44        CreateChildCommand.Helper {
45 
46        /**
47         * Default constructor
48         * @param adapterFactory Decorated adapter factory
49         */
50        public PalladioItemProvider(AdapterFactory adapterFactory) {
51                super(adapterFactory);
52        }
53 
54        /* (non-Javadoc)
55         * @see org.eclipse.emf.edit.provider.ItemProviderDecorator#getText(java.lang.Object)
56         * A label getter which is aware of the PCM
57         */
58        @Override
59        public String getText(Object object) {
60                String result = "";
61                if (object instanceof PCMRandomVariable) {
62                        String label = ((PCMRandomVariable)object).getSpecification();
63                        if (label == null) label = "";
64 
65                        String containingFeature = ((PCMRandomVariable)object).eContainingFeature().getName();
66                        containingFeature = containingFeature.split("_")[0];
67                        containingFeature = containingFeature.substring(0, 1).toUpperCase() + containingFeature.substring(1);
68                        return containingFeature + ": " + label + " <PCM Random Variable>";
69                }
70                if (object instanceof AssemblyContext) {
71                        AssemblyContext ctx = (AssemblyContext)object;
72                        result = ctx.getEntityName();
73                        result += ctx.getEncapsulatedComponent__AssemblyContext() == null ? "" : " <Component: "+ctx.getEncapsulatedComponent__AssemblyContext().getEntityName()+">";
74                } else if (object instanceof ProcessingResourceSpecification) { 
75                        ProcessingResourceSpecification spec = (ProcessingResourceSpecification) object;
76                        result += "Processing Resource ";
77                        if (spec.getActiveResourceType_ActiveResourceSpecification() != null)
78                                result += spec.getActiveResourceType_ActiveResourceSpecification().getEntityName() + ": ";
79                        else
80                                result += "<unset>: ";
81                        result += "Cores: ";
82                        result += spec.getNumberOfReplicas();
83                        result += " Rate: ";
84                        if (spec.getProcessingRate_ProcessingResourceSpecification() != null)
85                                if (spec.getProcessingRate_ProcessingResourceSpecification().getSpecification() != null) {
86                                        result += spec.getProcessingRate_ProcessingResourceSpecification().getSpecification() + " ";
87                                }
88                                else {
89                                        result += "N/A ";
90                                }
91                        else
92                                result += "N/A ";
93                        result += "Scheduling: "+spec.getSchedulingPolicy().getLiteral();
94                } else if (object instanceof Entity) {
95                        result = ((Entity)object).getEntityName();
96                } else if (object instanceof ResourceDemandingSEFF){
97                        ResourceDemandingSEFF seff = (ResourceDemandingSEFF) object;
98                        result = "SEFF " + (seff.getDescribedService__SEFF() == null ? "" : seff.getDescribedService__SEFF().getEntityName());
99                } else {
100                        if (object instanceof EObject && new RepositoryPrinter().doSwitch((EObject)object)!=null)
101                                result = (String) new RepositoryPrinter().doSwitch((EObject)object);
102                        else
103                                result = super.getText(object); 
104                }
105                if (object instanceof EObject)
106                {
107                        result += " <"+((EObject)object).eClass().getName()+"> ";
108                }
109                if (object instanceof Identifier)
110                {
111                        result += " [ID: " + ((Identifier)object).getId() + "]";
112                }
113                return result; 
114        }
115 
116        public Notifier getTarget() {
117                return ((Adapter)getDecoratedItemProvider()).getTarget();
118        }
119 
120        public void setTarget(Notifier newTarget) {
121                ((Adapter)getDecoratedItemProvider()).setTarget(newTarget);
122        }
123 
124        public String getCreateChildDescription(Object owner, Object feature,
125                        Object child, Collection<?> selection) {
126                return ((CreateChildCommand.Helper)getDecoratedItemProvider()).getCreateChildDescription(owner, feature, child, selection);
127        }
128 
129        public Object getCreateChildImage(Object owner, Object feature,
130                        Object child, Collection<?> selection) {
131                return ((CreateChildCommand.Helper)getDecoratedItemProvider()).getCreateChildImage(owner, feature, child, selection);
132        }
133 
134        public Collection<?> getCreateChildResult(Object child) {
135                return ((CreateChildCommand.Helper)getDecoratedItemProvider()).getCreateChildResult(child);
136        }
137 
138        public String getCreateChildText(Object owner, Object feature,
139                        Object child, Collection<?> selection) {
140                if (selection.size() == 1) {
141                        if (owner instanceof EObject) {
142                                if (feature instanceof EReference) {
143                                        String a = palladioConvention(((EReference)feature).getName());
144                                        String b = ((EObject)child).eClass().getName();
145                                        if (a.replaceAll(" ","").toLowerCase().equals(b.toLowerCase())) {
146                                                return PCMBenchUIPlugin.INSTANCE.getString(
147                                                                "_UI_CreateChild_palladio_simple", 
148                                                                new Object[] {b}, 
149                                                                true);
150                                        } else
151                                                return PCMBenchUIPlugin.INSTANCE.getString(
152                                                        "_UI_CreateChild_palladio", 
153                                                        new Object[] {a,b}, 
154                                                        true);
155                                }
156                        }
157                }
158                return ((CreateChildCommand.Helper)getDecoratedItemProvider()).getCreateChildText(owner, feature, child, selection);
159        }
160 
161        private String palladioConvention(String originalName) {
162                if (originalName.indexOf("_") >= 0) {
163                        originalName = originalName.substring(0, originalName.indexOf("_"));
164                        if (originalName.length() >= 1) {
165                                String newOriginalName = Character.toUpperCase(originalName.charAt(0))+""; 
166                                for (int i=1; i < originalName.length(); i++) {
167                                        if (Character.isUpperCase(originalName.charAt(i))) {
168                                                newOriginalName += " ";
169                                        }
170                                        newOriginalName += originalName.charAt(i);
171                                }
172                                originalName = newOriginalName;
173                        }
174                }
175                return originalName;
176        }
177 
178        public String getCreateChildToolTipText(Object owner, Object feature,
179                        Object child, Collection<?> selection) {
180                return ((CreateChildCommand.Helper)getDecoratedItemProvider()).getCreateChildToolTipText(owner, feature, child, selection);
181        }
182 
183        @Override
184        public Command createCommand(Object object, EditingDomain domain,
185                        Class<? extends Command> commandClass,
186                        CommandParameter commandParameter) {
187                if (commandClass == CreateChildCommand.class)
188            {
189              CommandParameter newChildParameter = (CommandParameter)commandParameter.getValue();
190              return new CreateChildCommand
191                  (domain,
192                   commandParameter.getEOwner(), 
193                   newChildParameter.getEStructuralFeature(), 
194                   newChildParameter.getValue(),
195                   newChildParameter.getIndex(),
196                   commandParameter.getCollection(),
197                   this);      
198            }
199                return super.createCommand(object, domain, commandClass, commandParameter);
200        }
201        
202        
203        
204}

[all classes][de.uka.ipd.sdq.pcmbench.ui.provider]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov