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