1 | package de.uka.ipd.sdq.pcm.dialogs.exception; |
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.jface.viewers.TableViewer; |
11 | import org.eclipse.swt.widgets.TableItem; |
12 | |
13 | import de.uka.ipd.sdq.pcm.repository.ExceptionType; |
14 | |
15 | /** author roman */ |
16 | public class ExceptionsCellModifier implements ICellModifier { |
17 | |
18 | private List<String> columnNames; |
19 | private ExceptionType exceptionType; |
20 | private TableViewer viewer; |
21 | |
22 | /** |
23 | * The transactional editing domain which is used to get the commands and |
24 | * alter the model |
25 | */ |
26 | protected TransactionalEditingDomain editingDomain = null; |
27 | |
28 | public ExceptionsCellModifier(TableViewer viewer, TransactionalEditingDomain editingDomain) { |
29 | this.columnNames = Arrays.asList(ExceptionsDialog.getColumnNames()); |
30 | this.editingDomain = editingDomain; |
31 | this.viewer = viewer; |
32 | } |
33 | |
34 | /* (non-Javadoc) |
35 | * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, |
36 | * java.lang.String) |
37 | */ |
38 | public boolean canModify(Object element, String property) { |
39 | return true; |
40 | } |
41 | |
42 | /* (non-Javadoc) |
43 | * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, |
44 | * java.lang.String) |
45 | */ |
46 | public Object getValue(Object element, String property) { |
47 | return (new ExceptionsItemProvider(null)).getColumnText(element, |
48 | columnNames.indexOf(property)); |
49 | } |
50 | |
51 | /* (non-Javadoc) |
52 | * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, |
53 | * java.lang.String, java.lang.Object) |
54 | */ |
55 | public void modify(Object element, String property, Object value) { |
56 | |
57 | // Find the index of the column |
58 | int columnIndex = columnNames.indexOf(property); |
59 | |
60 | Assert.isNotNull(element); |
61 | TableItem item = (TableItem) element; |
62 | exceptionType = (ExceptionType) item.getData(); |
63 | |
64 | switch (columnIndex) { |
65 | case ExceptionsDialog.ICON_COLUMN_INDEX: // COMPLETED_COLUMN |
66 | break; |
67 | case ExceptionsDialog.CONTEXT_COLUMN_INDEX: // RETURNTYPE_COLUMN |
68 | break; |
69 | case ExceptionsDialog.NAME_COLUMN_INDEX: // SERVICENAME_COLUMN |
70 | String valueString = ((String) value).trim(); |
71 | setExceptionName(valueString); |
72 | break; |
73 | default: |
74 | } |
75 | } |
76 | |
77 | |
78 | /** |
79 | * Set ExceptionName of the selected Signature |
80 | */ |
81 | private void setExceptionName(final String value) { |
82 | |
83 | RecordingCommand recCommand = new RecordingCommand(editingDomain) { |
84 | @Override |
85 | protected void doExecute() { |
86 | exceptionType.setExceptionName(value); |
87 | } |
88 | }; |
89 | |
90 | if (!value.equals(exceptionType.getExceptionName())) { |
91 | recCommand.setLabel("Set ParameterName"); |
92 | editingDomain.getCommandStack().execute(recCommand); |
93 | |
94 | /** Refresh TableViewer*/ |
95 | viewer.refresh(); |
96 | } |
97 | } |
98 | } |