| 1 | /** |
| 2 | * |
| 3 | */ |
| 4 | package de.uka.ipd.sdq.pcmbench.ui.provider; |
| 5 | |
| 6 | import java.util.Collection; |
| 7 | |
| 8 | import org.eclipse.emf.common.command.Command; |
| 9 | import org.eclipse.emf.common.notify.Adapter; |
| 10 | import org.eclipse.emf.common.notify.AdapterFactory; |
| 11 | import org.eclipse.emf.common.notify.Notifier; |
| 12 | import org.eclipse.emf.ecore.EObject; |
| 13 | import org.eclipse.emf.ecore.EReference; |
| 14 | import org.eclipse.emf.edit.command.CommandParameter; |
| 15 | import org.eclipse.emf.edit.command.CreateChildCommand; |
| 16 | import org.eclipse.emf.edit.domain.EditingDomain; |
| 17 | import org.eclipse.emf.edit.provider.IEditingDomainItemProvider; |
| 18 | import org.eclipse.emf.edit.provider.IItemLabelProvider; |
| 19 | import org.eclipse.emf.edit.provider.IItemPropertySource; |
| 20 | import org.eclipse.emf.edit.provider.IStructuredItemContentProvider; |
| 21 | import org.eclipse.emf.edit.provider.ITreeItemContentProvider; |
| 22 | import org.eclipse.emf.edit.provider.ItemProviderDecorator; |
| 23 | |
| 24 | import de.uka.ipd.sdq.identifier.Identifier; |
| 25 | import de.uka.ipd.sdq.pcm.core.PCMRandomVariable; |
| 26 | import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext; |
| 27 | import de.uka.ipd.sdq.pcm.core.entity.Entity; |
| 28 | import de.uka.ipd.sdq.pcm.resourceenvironment.ProcessingResourceSpecification; |
| 29 | import de.uka.ipd.sdq.pcm.seff.ResourceDemandingSEFF; |
| 30 | import 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 | */ |
| 37 | public 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 | } |