| 1 | package de.uka.ipd.sdq.pcmbench.tabs.operations; |
| 2 | |
| 3 | import java.util.Arrays; |
| 4 | import java.util.List; |
| 5 | |
| 6 | import org.eclipse.core.runtime.Assert; |
| 7 | import org.eclipse.emf.transaction.RecordingCommand; |
| 8 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
| 9 | import org.eclipse.emf.transaction.util.TransactionUtil; |
| 10 | import org.eclipse.swt.widgets.TableItem; |
| 11 | |
| 12 | import de.uka.ipd.sdq.pcm.repository.InfrastructureSignature; |
| 13 | import de.uka.ipd.sdq.pcmbench.tabs.generic.ObservableCellModifier; |
| 14 | |
| 15 | /**Modifier for cells containing infrastructure signature descriptions. |
| 16 | * @author Roman Andrej |
| 17 | * @author groenda |
| 18 | */ |
| 19 | |
| 20 | public class InfrastructureSignaturesCellModifier extends ObservableCellModifier { |
| 21 | |
| 22 | /** Name of the columns. */ |
| 23 | private List<String> columnNames; |
| 24 | /** Signature. */ |
| 25 | private InfrastructureSignature signature; |
| 26 | |
| 27 | /** Editing domain for model modifications. */ |
| 28 | protected TransactionalEditingDomain editingDomain = null; |
| 29 | |
| 30 | /**Initializes a new instance. |
| 31 | */ |
| 32 | public InfrastructureSignaturesCellModifier() { |
| 33 | this.columnNames = Arrays.asList(InfrastructureSignaturesEditorSection.columnNames); |
| 34 | } |
| 35 | |
| 36 | /* (non-Javadoc) |
| 37 | * @see org.eclipse.jface.viewers.ICellModifier#canModify(Object element, |
| 38 | * String property) |
| 39 | */ |
| 40 | public boolean canModify(Object element, String property) { |
| 41 | return true; |
| 42 | } |
| 43 | |
| 44 | /* (non-Javadoc) |
| 45 | * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String) |
| 46 | */ |
| 47 | public Object getValue(Object element, String property) { |
| 48 | return (new InfrastructureSignaturesTabItemProvider(null)).getColumnText(element, |
| 49 | columnNames.indexOf(property)); |
| 50 | } |
| 51 | |
| 52 | public void modify(Object element, String property, Object value) { |
| 53 | |
| 54 | // Find the index of the column |
| 55 | int columnIndex = columnNames.indexOf(property); |
| 56 | |
| 57 | Assert.isNotNull(element); |
| 58 | TableItem item = (TableItem) element; |
| 59 | signature = (InfrastructureSignature) item.getData(); |
| 60 | editingDomain = TransactionUtil.getEditingDomain(signature); |
| 61 | |
| 62 | switch (columnIndex) { |
| 63 | case InfrastructureSignaturesEditorSection.ICON_COLUMN_INDEX: // COMPLETED_COLUMN |
| 64 | break; |
| 65 | case InfrastructureSignaturesEditorSection.SIGNATURENAME_COLUMN_INDEX: // SERVICENAME_COLUMN |
| 66 | String valueString = ((String) value).trim(); |
| 67 | setSignatureName(valueString); |
| 68 | break; |
| 69 | case InfrastructureSignaturesEditorSection.PARAMETER_COLUMN_INDEX: // OWNEDPARAMETER_COLUMN |
| 70 | break; |
| 71 | case InfrastructureSignaturesEditorSection.EXCEPTIONS_COLUMN_INDEX: // EXEPTIONTYPE_COLUM |
| 72 | break; |
| 73 | default: |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | /**Sets the name of the infrastructure signature. |
| 78 | * @param valueString New name. |
| 79 | */ |
| 80 | private void setSignatureName(String valueString) { |
| 81 | final String value = valueString; |
| 82 | |
| 83 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
| 84 | @Override |
| 85 | protected void doExecute() { |
| 86 | signature.setEntityName(value); |
| 87 | } |
| 88 | }; |
| 89 | |
| 90 | if (!value.equals(signature.getEntityName())) { |
| 91 | recCommand.setDescription("Edit Infrastructure Signature Property"); |
| 92 | recCommand.setLabel("Set signature name"); |
| 93 | editingDomain.getCommandStack().execute(recCommand); |
| 94 | } |
| 95 | } |
| 96 | } |