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

COVERAGE SUMMARY FOR SOURCE FILE [ComponentParametersCellModifier.java]

nameclass, %method, %block, %line, %
ComponentParametersCellModifier.java0%   (0/2)0%   (0/13)0%   (0/244)0%   (0/78)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class ComponentParametersCellModifier0%   (0/1)0%   (0/11)0%   (0/173)0%   (0/53)
ComponentParametersCellModifier (): void 0%   (0/1)0%   (0/15)0%   (0/6)
access$0 (ComponentParametersCellModifier): AssemblyContext 0%   (0/1)0%   (0/3)0%   (0/1)
access$1 (ComponentParametersCellModifier): VariableUsage 0%   (0/1)0%   (0/3)0%   (0/1)
access$2 (ComponentParametersCellModifier, AssemblyContext, VariableUsage): V... 0%   (0/1)0%   (0/5)0%   (0/1)
canModify (Object, String): boolean 0%   (0/1)0%   (0/15)0%   (0/6)
getValue (Object, String): Object 0%   (0/1)0%   (0/11)0%   (0/2)
isExisted (AssemblyContext, VariableUsage): VariableUsage 0%   (0/1)0%   (0/32)0%   (0/8)
modify (Object, String, Object): void 0%   (0/1)0%   (0/32)0%   (0/11)
setContext (AssemblyContext): void 0%   (0/1)0%   (0/4)0%   (0/2)
setSpecification (String, TableItem): void 0%   (0/1)0%   (0/46)0%   (0/13)
setTableItemColor (TableItem): void 0%   (0/1)0%   (0/7)0%   (0/2)
     
class ComponentParametersCellModifier$10%   (0/1)0%   (0/2)0%   (0/71)0%   (0/26)
ComponentParametersCellModifier$1 (ComponentParametersCellModifier, Transacti... 0%   (0/1)0%   (0/10)0%   (0/2)
doExecute (): void 0%   (0/1)0%   (0/61)0%   (0/24)

1package de.uka.ipd.sdq.pcmbench.tabs.parameters;
2 
3import java.util.Arrays;
4import java.util.List;
5 
6import org.eclipse.core.runtime.Assert;
7import org.eclipse.emf.common.util.EList;
8import org.eclipse.emf.transaction.RecordingCommand;
9import org.eclipse.emf.transaction.TransactionalEditingDomain;
10import org.eclipse.emf.transaction.util.TransactionUtil;
11import org.eclipse.swt.SWT;
12import org.eclipse.swt.widgets.TableItem;
13 
14import de.uka.ipd.sdq.pcm.core.CoreFactory;
15import de.uka.ipd.sdq.pcm.core.PCMRandomVariable;
16import de.uka.ipd.sdq.pcm.core.composition.AssemblyContext;
17import de.uka.ipd.sdq.pcm.parameter.VariableCharacterisation;
18import de.uka.ipd.sdq.pcm.parameter.VariableUsage;
19import de.uka.ipd.sdq.pcm.stochasticexpressions.PCMStoExPrettyPrintVisitor;
20import de.uka.ipd.sdq.pcmbench.tabs.generic.ObservableCellModifier;
21 
22/**
23 * The class define a cell modifier is used to access the data model from a cell
24 * editor.
25 * 
26 * @author Roman Andrej
27 */
28public class ComponentParametersCellModifier extends ObservableCellModifier {
29 
30        private List<String> columnNames;
31        private VariableUsageWrapper wrapper;
32        
33        /** In property view selected VariableUsage. */
34        private VariableUsage variableUsage;
35        /** In diagram selected AssemblyContext. */
36        private AssemblyContext context;
37        /** The value wont for print VariableUsage name uses. */
38        private PCMStoExPrettyPrintVisitor print;
39 
40        /**
41         * The transactional editing domain which is used to get the commands and
42         * alter the model
43         */
44        protected TransactionalEditingDomain editingDomain = null;
45 
46        public ComponentParametersCellModifier() {
47                this.columnNames = Arrays
48                                .asList(ComponentParametersEditorSection.columnNames);
49                this.print = new PCMStoExPrettyPrintVisitor();
50        }
51 
52        /**
53         * {@inheritDoc}
54         */
55        public boolean canModify(Object element, String property) {
56 
57                int columnIndex = columnNames.indexOf(property);
58 
59                switch (columnIndex) {
60                case ComponentParametersEditorSection.ICON_COLUMN_INDEX:
61                        return false;
62                case ComponentParametersEditorSection.VARIABLE_COLUMN_INDEX:
63                        return false;
64                case ComponentParametersEditorSection.STOEX_COLUMN_INDEX:
65                        return true;
66                default:
67                        break;
68                }
69 
70                return true;
71        }
72 
73        /**
74         * {@inheritDoc}
75         */
76        public Object getValue(Object element, String property) {
77                return (new ParametersTabItemProvider(null)).getColumnText(element,
78                                columnNames.indexOf(property));
79        }
80 
81        /**
82         * {@inheritDoc}
83         */
84        public void modify(Object element, String property, Object value) {
85                // Find the index of the column
86                int columnIndex = columnNames.indexOf(property);
87 
88                Assert.isNotNull(element);
89                TableItem item = (TableItem) element;
90 
91                wrapper = (VariableUsageWrapper) item.getData();
92                variableUsage = wrapper.getVariableUsage();
93 
94                switch (columnIndex) {
95                case ComponentParametersEditorSection.ICON_COLUMN_INDEX:
96                        break;
97                case ComponentParametersEditorSection.VARIABLE_COLUMN_INDEX:
98                        break;
99                case ComponentParametersEditorSection.STOEX_COLUMN_INDEX:
100                        setSpecification(((String) value).trim(), item);
101                        break;
102                default:
103                        break;
104                }
105 
106        }
107 
108        /**
109         * Update Specification of selected VariableUsage.
110         */
111        private void setSpecification(final String value, TableItem item) {
112                editingDomain = TransactionUtil.getEditingDomain(variableUsage);
113 
114                VariableCharacterisation variableCharacterisation = variableUsage
115                                .getVariableCharacterisation_VariableUsage().get(0);
116 
117                if (!variableCharacterisation
118                                .getSpecification_VariableCharacterisation().getSpecification()
119                                .equals(value)) {
120 
121                        RecordingCommand recCommand = new RecordingCommand(editingDomain) {
122                                @Override
123                                protected void doExecute() {
124 
125                                        // create/set RandomVariable
126                                        PCMRandomVariable randomVariable = CoreFactory.eINSTANCE
127                                                        .createPCMRandomVariable();
128                                        randomVariable.setSpecification(value);
129 
130                                        // test if VariableUsaged exist
131                                        VariableUsage existedVariableUsage = isExisted(context,
132                                                        variableUsage);
133 
134                                        if (existedVariableUsage == null) {
135                                                VariableUsage contexVariableUsage = null;
136 
137                                                // create VariableUsage for AssemblyContext
138                                                ParameterUtil copier = new ParameterUtil();
139                                                contexVariableUsage = (VariableUsage) copier
140                                                                .copy(variableUsage);
141                                                copier.copyReferences();
142 
143                                                // create VariableCharacterisation for AssemblyContext
144                                                VariableCharacterisation characterisation = contexVariableUsage
145                                                                .getVariableCharacterisation_VariableUsage()
146                                                                .get(0);
147                                                // set specification
148                                                characterisation
149                                                                .setSpecification_VariableCharacterisation(randomVariable);
150                                                // add edited VariableUsage to AssemblyContext
151 
152                                                context.getConfigParameterUsages__AssemblyContext().add(
153                                                                contexVariableUsage);
154                                        } else {
155                                                // create VariableCharacterisation for AssemblyContext
156                                                VariableCharacterisation characterisation = existedVariableUsage
157                                                                .getVariableCharacterisation_VariableUsage()
158                                                                .get(0);
159                                                // set specification
160                                                characterisation
161                                                                .setSpecification_VariableCharacterisation(randomVariable);
162 
163                                        }
164 
165                                }
166                        };
167 
168                        recCommand.setLabel("Set specification");
169                        editingDomain.getCommandStack().execute(recCommand);
170                        // set color for TableItem
171                        setTableItemColor(item);
172                        // make TableItem edited
173                        wrapper.setEdited(true);
174                        // update observer
175                        notifyObservers(wrapper);
176 
177                }
178        }
179 
180        /**
181         * The Method test if VariableUsage already exist in the AssemblyContext.
182         * Return null if VarableUsage not exist this AssemblyContect.
183         * 
184         * @param contex
185         *            The associated AssembyContex
186         * @param newVariable
187         *            The associated VariableUsage
188         * @return
189         */
190        private VariableUsage isExisted(AssemblyContext context,
191                        VariableUsage newVariable) {
192                EList<VariableUsage> variables = context
193                                .getConfigParameterUsages__AssemblyContext();
194 
195                String newName = print.prettyPrint(newVariable);
196                for (VariableUsage existedVariable : variables) {
197                        String existedName = print.prettyPrint(existedVariable);
198                        if (newName.equals(existedName)) {
199                                return existedVariable;
200                        }
201                }
202                return null;
203        }
204 
205        private void setTableItemColor(TableItem item) {
206                item.setForeground(item.getDisplay().getSystemColor(SWT.COLOR_BLACK));
207        }
208 
209        /**
210         * @param context
211         *            the context to set
212         */
213        public void setContext(AssemblyContext context) {
214                this.context = context;
215        }
216}

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