1 | package de.uka.ipd.sdq.pcmbench.tabs.operations; |
2 | |
3 | |
4 | import java.util.ArrayList; |
5 | |
6 | import org.eclipse.emf.ecore.EObject; |
7 | import org.eclipse.emf.ecore.EReference; |
8 | import org.eclipse.emf.transaction.TransactionalEditingDomain; |
9 | import org.eclipse.emf.transaction.util.TransactionUtil; |
10 | import org.eclipse.jface.dialogs.Dialog; |
11 | import org.eclipse.jface.viewers.CellEditor; |
12 | import org.eclipse.jface.viewers.DialogCellEditor; |
13 | import org.eclipse.jface.viewers.TextCellEditor; |
14 | import org.eclipse.swt.SWT; |
15 | import org.eclipse.swt.events.SelectionListener; |
16 | import org.eclipse.swt.widgets.Composite; |
17 | import org.eclipse.swt.widgets.Control; |
18 | import org.eclipse.swt.widgets.Table; |
19 | import org.eclipse.swt.widgets.TableColumn; |
20 | |
21 | import de.uka.ipd.sdq.pcm.dialogs.datatype.CallDataTypeDialog; |
22 | import de.uka.ipd.sdq.pcm.dialogs.parameters.ParametersDialog; |
23 | import de.uka.ipd.sdq.pcm.repository.DataType; |
24 | import de.uka.ipd.sdq.pcm.repository.Repository; |
25 | import de.uka.ipd.sdq.pcm.repository.Signature; |
26 | import de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection; |
27 | import de.uka.ipd.sdq.pcmbench.tabs.generic.ObservableCellModifier; |
28 | |
29 | public class OperationsEditorSection extends EditorSection{ |
30 | |
31 | public static final int ICON_COLUMN_INDEX = 0; |
32 | public static final int RETURNTYPE_COLUMN_INDEX = 1; |
33 | public static final int SIGNATURENAME_COLUMN_INDEX = 2; |
34 | public static final int PARAMETER_COLUMN_INDEX = 3; |
35 | public static final int EXCEPTIONS_COLUMN_INDEX = 4; |
36 | |
37 | /** |
38 | * Columns of a table, which is used into operations table |
39 | */ |
40 | public final static String OPERATIONS_ICON_COLUMN = ""; |
41 | public final static String OWNEDPARAMETER_COLUMN = "OwnedParameters"; |
42 | public final static String RETURNTYPE_COLUMN = "ReturnType"; |
43 | public final static String SERVICENAME_COLUMN = "ServiceName"; |
44 | public final static String EXEPTIONTYPE_COLUM = "ExeptionType"; |
45 | |
46 | // Set column names of Tabele |
47 | public static String[] columnNames = new String[] { OPERATIONS_ICON_COLUMN,RETURNTYPE_COLUMN, |
48 | SERVICENAME_COLUMN, OWNEDPARAMETER_COLUMN, EXEPTIONTYPE_COLUM }; |
49 | |
50 | /** Define the Add-Button listener. Listener must by later initialized. */ |
51 | private OperationAddActionListener addButtonListener; |
52 | |
53 | /** Constructor */ |
54 | public OperationsEditorSection(Composite composite) { |
55 | super(composite); |
56 | } |
57 | |
58 | /* (non-Javadoc) |
59 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createViewerCellEditors(org.eclipse.swt.widgets.Table) |
60 | */ |
61 | @Override |
62 | protected CellEditor[] createViewerCellEditors(Table table) { |
63 | CellEditor[] editors = new CellEditor[columnNames.length]; |
64 | |
65 | editors[SIGNATURENAME_COLUMN_INDEX] = new TextCellEditor(table); |
66 | |
67 | // create 'DeleteCellValueListener' and as SelectionListener to the 'TableVewer' |
68 | OperationDeleteCellValueListener cellValueListener = new OperationDeleteCellValueListener(viewer); |
69 | viewer.addSelectionChangedListener(cellValueListener); |
70 | |
71 | editors[RETURNTYPE_COLUMN_INDEX] = new TypeDialogCellEditor(table, |
72 | cellValueListener) { |
73 | |
74 | /* (non-Javadoc) |
75 | * @see org.eclipse.jface.viewers.DialogCellEditor#openDialogBox(org.eclipse.swt.widgets.Control) |
76 | */ |
77 | @Override |
78 | protected Object openDialogBox(Control cellEditorWindow) { |
79 | TransactionalEditingDomain editingDomain = TransactionUtil |
80 | .getEditingDomain(getSelectedSignature()); |
81 | |
82 | ArrayList<Object> filterList = new ArrayList<Object>(); |
83 | filterList.add(DataType.class); |
84 | filterList.add(Repository.class); |
85 | ArrayList<EReference> additionalReferences = new ArrayList<EReference>(); |
86 | |
87 | CallDataTypeDialog dialog = new CallDataTypeDialog( |
88 | cellEditorWindow.getShell(), filterList, |
89 | additionalReferences, editingDomain.getResourceSet()); |
90 | dialog.setProvidedService(DataType.class); |
91 | dialog.open(); |
92 | |
93 | if (!(dialog.getResult() instanceof DataType)) |
94 | return null; |
95 | |
96 | return dialog.getResult(); |
97 | } |
98 | }; |
99 | |
100 | editors[PARAMETER_COLUMN_INDEX] = new DialogCellEditor(table) { |
101 | @Override |
102 | protected Object openDialogBox(Control cellEditorWindow) { |
103 | ParametersDialog dialog = new ParametersDialog(cellEditorWindow |
104 | .getShell(), getSelectedSignature()); |
105 | if (dialog.open() == Dialog.OK) |
106 | viewer.refresh(); |
107 | return null; |
108 | } |
109 | }; |
110 | |
111 | return editors; |
112 | } |
113 | |
114 | /* (non-Javadoc) |
115 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createViewerCellModifier() |
116 | */ |
117 | @Override |
118 | protected ObservableCellModifier createViewerCellModifier() { |
119 | return new OperationsCellModifier(); |
120 | } |
121 | |
122 | /* (non-Javadoc) |
123 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createTableColumns(org.eclipse.swt.widgets.Table) |
124 | */ |
125 | @Override |
126 | protected void createTableColumns(Table table) { |
127 | // 1st column |
128 | TableColumn column = new TableColumn(table, SWT.CENTER, 0); |
129 | column.setText(""); |
130 | column.setWidth(25); |
131 | |
132 | for (int i = 1; i < columnNames.length; i++) { |
133 | // n-te column with task Description |
134 | column = new TableColumn(table, SWT.LEFT, i); |
135 | column.setText((String) columnNames[i]); |
136 | column.setWidth(140); |
137 | } |
138 | } |
139 | |
140 | /* (non-Javadoc) |
141 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createAddButtonActionListener() |
142 | */ |
143 | @Override |
144 | protected SelectionListener createAddButtonActionListener() { |
145 | // the value must by initialized! (don't return new AddActionListener()) |
146 | this.addButtonListener = new OperationAddActionListener(); |
147 | |
148 | return addButtonListener; |
149 | } |
150 | |
151 | /* (non-Javadoc) |
152 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#createDeleteButtonListener() |
153 | */ |
154 | @Override |
155 | protected SelectionListener createDeleteButtonListener() { |
156 | return new OperationDeleteActionListener(); |
157 | } |
158 | |
159 | /* (non-Javadoc) |
160 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#getViewerColumnProperties() |
161 | */ |
162 | @Override |
163 | protected String[] getTableColumnNames() { |
164 | return columnNames; |
165 | } |
166 | |
167 | /* (non-Javadoc) |
168 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#canAddButonCreated() |
169 | */ |
170 | @Override |
171 | protected boolean canAddButonCreated() { |
172 | return true; |
173 | } |
174 | |
175 | /* (non-Javadoc) |
176 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#canDeleteButonCreated() |
177 | */ |
178 | @Override |
179 | protected boolean canDeleteButonCreated() { |
180 | return true; |
181 | } |
182 | |
183 | /* (non-Javadoc) |
184 | * @see de.uka.ipd.sdq.pcmbench.tabs.generic.EditorSection#inputValidation(org.eclipse.emf.ecore.EObject) |
185 | */ |
186 | @Override |
187 | protected boolean inputValidation(EObject object) { |
188 | return true; |
189 | } |
190 | |
191 | public Signature getSelectedSignature() { |
192 | return (Signature) getSelectedObject(); |
193 | } |
194 | |
195 | /** |
196 | * @return the addButtonListener |
197 | */ |
198 | public OperationAddActionListener getAddButtonListener() { |
199 | return addButtonListener; |
200 | } |
201 | } |