1 | package de.uka.ipd.sdq.pcm.dialogs.datatype; |
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.jface.viewers.ICellModifier; |
10 | import org.eclipse.swt.widgets.TableItem; |
11 | |
12 | import de.uka.ipd.sdq.pcm.dialogs.parameters.CreateEditorContents; |
13 | import de.uka.ipd.sdq.pcm.repository.DataType; |
14 | import de.uka.ipd.sdq.pcm.repository.InnerDeclaration; |
15 | |
16 | public class InnerDeclarationCellModifier implements ICellModifier { |
17 | |
18 | private PalladioDataTypeDialog dialog; |
19 | private List<String> columnNames; |
20 | private InnerDeclaration declaration; |
21 | |
22 | private TransactionalEditingDomain editingDomain; |
23 | |
24 | public InnerDeclarationCellModifier(PalladioDataTypeDialog dialog, TransactionalEditingDomain editingDomain) { |
25 | this.editingDomain = editingDomain; |
26 | this.dialog = dialog; |
27 | this.columnNames = Arrays.asList(CreateEditorContents |
28 | .getColumnNames()); |
29 | } |
30 | |
31 | /* (non-Javadoc) |
32 | * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, |
33 | * java.lang.String) |
34 | */ |
35 | public boolean canModify(Object element, String property) { |
36 | return true; |
37 | } |
38 | |
39 | /* (non-Javadoc) |
40 | * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, |
41 | * java.lang.String) |
42 | */ |
43 | public Object getValue(Object element, String property) { |
44 | return (new InnerDeclarationItemProvider(null)).getColumnText(element, |
45 | columnNames.indexOf(property)); |
46 | } |
47 | |
48 | /* (non-Javadoc) |
49 | * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, |
50 | * java.lang.String, java.lang.Object) |
51 | */ |
52 | public void modify(Object element, String property, Object value) { |
53 | // Find the index of the column |
54 | int columnIndex = columnNames.indexOf(property); |
55 | |
56 | Assert.isNotNull(element); |
57 | TableItem item = (TableItem) element; |
58 | declaration = (InnerDeclaration) item.getData(); |
59 | |
60 | switch (columnIndex) { |
61 | case CreateEditorContents.ICON_COLUMN_INDEX: // COMPLETED_COLUMN |
62 | break; |
63 | case CreateEditorContents.CONTEXT_COLUMN_INDEX: // RETURNTYPE_COLUMN |
64 | break; |
65 | case CreateEditorContents.NAME_COLUMN_INDEX: // SERVICENAME_COLUMN |
66 | String valueString = ((String) value).trim(); |
67 | setDeclarationName(valueString); |
68 | break; |
69 | case CreateEditorContents.TYPE_COLUMN_INDEX: // OWNEDPARAMETER_COLUMN |
70 | if (value instanceof DataType) { |
71 | DataType valueDataType = (DataType) value; |
72 | setDataType(valueDataType); |
73 | } |
74 | break; |
75 | default: |
76 | } |
77 | } |
78 | |
79 | /** |
80 | * @param - inner datatype of declaration |
81 | */ |
82 | private void setDataType(final DataType dataType) { |
83 | |
84 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
85 | @Override |
86 | protected void doExecute() { |
87 | declaration.setDatatype_InnerDeclaration(dataType); |
88 | } |
89 | }; |
90 | |
91 | if (!dataType.equals(declaration.getDatatype_InnerDeclaration())) { |
92 | recCommand.setLabel("Set InnerDeclaration DataType"); |
93 | editingDomain.getCommandStack().execute(recCommand); |
94 | } |
95 | reloadDeclarationViewer(); |
96 | } |
97 | |
98 | /** set the name of innerdeclaration */ |
99 | private void setDeclarationName(final String valueString) { |
100 | |
101 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
102 | @Override |
103 | protected void doExecute() { |
104 | declaration.setEntityName(valueString); |
105 | } |
106 | }; |
107 | |
108 | if (!valueString.equals(declaration.getEntityName())) { |
109 | recCommand.setLabel("Set InnerDeclaration name"); |
110 | editingDomain.getCommandStack().execute(recCommand); |
111 | } |
112 | |
113 | reloadDeclarationViewer(); |
114 | } |
115 | |
116 | private void reloadDeclarationViewer() { |
117 | dialog.refresh(); |
118 | } |
119 | } |